Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 190561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:16:00+00:00 2026-05-11T16:16:00+00:00

Given my two db tables aliases and subscriber have entries like this: aliases.username =

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:16:00+00:00Added an answer on May 11, 2026 at 4:16 pm
    SELECT  aliases.username AS phone_number,
            subscriber.username AS user_name
    FROM    aliases, subscriber
    WHERE   aliases.contact REGEXP CONCAT('^sip:', subscriber.user_name, '[.*]')
    

    Note that the following query will be more efficient:

    SELECT  aliases.username AS phone_number,
            subscriber.username AS user_name
    FROM    aliases, subscriber
    WHERE   aliases.contact LIKE CONCAT('sip:', subscriber.user_name, '%')
    

    , and this one, though seems complex, is even more efficient:

    CREATE FUNCTION fn_get_next_subscriber(initial VARCHAR(200)) RETURNS VARCHAR(200)
    NOT DETERMINISTIC
    READS SQL DATA
    BEGIN
            DECLARE _username VARCHAR(200);
            DECLARE EXIT HANDLER FOR NOT FOUND RETURN UNHEX('FFFF');
            SELECT  username
            INTO    _username
            FROM    subscribers
            WHERE   username>= initial
                    AND username NOT LIKE CONCAT(initial, '%')
            ORDER BY
                    username
            LIMIT 1;
            RETURN _username;
    END
    
    SELECT  a.username AS phone_number,
            s.username AS user_name
    FROM    (
            SELECT  si.*, CONCAT('sip:', username) AS fromcontact
            FROM    subscriber si
            ) s, aliases a
    WHERE   a.contact >= fromcontact
            AND a.contact < fn_get_next_subscriber(fromcontact)
    

    This will use an index on aliases (contact) and avoid full table scan.

    See this article in my blog:

    • Article-aware title filtering: internationalization: how to JOIN efficiently on a LIKE condition
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that look a little like this AGR_TERR_DEF_TERRS ID DEF_ID TERRITORY_ID
Given that I have two tables Customer (id int, username varchar) Order (customer_id int,
Given two tables like this: Date | Client | Category | Amount1 | x
I have two tables, stats and stat_log. The stat log is like this: user_id,stat_id,value,registered
Problem Given the following two tables, I'd like to select all Ids for Posts
Given a database with two tables X and Y , I have a query
I have 10 tables in my database(MySQL). two of them is given below tbl_state
I have two tables, like so: table a contains: id|name stock1|fullname stock2|fullname2 stock3|fullname3 table
I have a database with some relations. I have two tables in this example:
Given the following two tables: users (user_id, username, location, email) votes (user_id, value, date,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.