Given my two db tables aliases and subscriber have entries like this:
aliases.username = '5551234567'
aliases.contact = 'sip:a_sip_username@sip.domain.com'
subscriber.username = 'a_sip_username'
I’d like to select only the matching rows that have subscriber.username within the aliases.contact field. This was my first attempt but it doesn’t return anything:
SELECT
aliases.username as phone_number,
(@B:=subscriber.username) as user_name
FROM aliases,subscriber
WHERE aliases.contact regexp "^sip:@B[.*]"
Is this even possible or should I move the logic to the application?
Note that the following query will be more efficient:
, and this one, though seems complex, is even more efficient:
This will use an index on
aliases (contact)and avoid full table scan.See this article in my blog:
JOINefficiently on aLIKEcondition