Mysql: setting a variable within the select -
My two DB tables have entries like aliases and client seeing in this way:
Aliases.username = '5551234567' aliases.contact = 'sip: a_sip_username@sip.domain.com' subscriber.username = 'a_sip_username' I only select those matching rows I want the customers whose customers are inside the Aliases.contact field. User name. This was my first attempt, but it has not returned anything:
SELECT # aliases.username phone_number,
(@B: = subscriber.username) as user_name
By nickname, customer - WHERE alias.contact regexp "^ sip: @B [. *]"
Is it possible or should I take the argument to the application ?
select aliases.username as phone_number, subscriber.username as user_name aliases, customer Where Aliases.contact REGEXP CONCAT ('^ sip:', subscriber.user_name, '[. *]') Note that the following questions will be more efficient:
SELECT aliases.username as phone_number, subscriber.username As the name of the consumer from the nickname, where the nickname Context-like concrete ('sip:', subscriber.user_name, '%') , and this one seems complex, even more efficient:
function F N_get_next_subscriber (the initial VARCHAR (200)) VARCHAR (200) does not rotate the nickticomic reads SQL data; _UARCHER VARCHAR (200); UNHEEX returns for 'Disapproved Extender Handler' ('FFFF') not found; Select the Username from the user name, where username & gt; = Username no limit to 1 for initial and user name concrete (initial, '%'); Return_username; Select END as a.username as phone_number, s.username as user_name (SELECT SI. *, CONCAT (contact 'sip:', username) AS), surname a WHERE a.contact & gt; = Contact from and contact a & lt; Avoid aliases (contact) and full table scans. View this article in my blog:
- :
join as like How to skillfully
Comments
Post a Comment