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 7683529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:48:56+00:00 2026-05-31T18:48:56+00:00

I need to make a synonym search function, using MySQL. Here is the tables

  • 0

I need to make a synonym search function, using MySQL.

Here is the tables structure :

NAMES_TABLE           SYNONYMS_TABLE
------------          --------------
ID | NAME              ID_1 | ID_2
---+--------          ------+-------
1  | NAME_A              1  |  2
2  | NAME_B              2  |  1
3  | NAME_C              1  |  3
4  | NAME_D              3  |  1
5  | NAME_E              4  |  5
                         5  |  4  

I want it to work like this : entering a word in a form that is in the sends me all the words corresponding, where their indexes are in the synonyms table, as ID_1 or ID_2.

But I can’t figure out to make the request…

Thanks for your help.

  • 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-31T18:48:57+00:00Added an answer on May 31, 2026 at 6:48 pm

    One directional: ID_1 is a name, ID_2 is a synonym:

    select
      sn.NAME
    from
      NAMES_TABLE n
      inner join SYNONYMS_TABLE s on s.ID_1 = n.ID
      inner join NAMES_TABLE sn on sn.ID2 = s.ID_2
    where
      n.NAME = :NAME
    

    Two directional: either ID_1 or ID_2 can contain a name, while the other is its synonym.

    select
      sn1.NAME
    from
      NAMES_TABLE n1
      inner join SYNONYMS_TABLE s1 on s1.ID_1 = n1.ID
      inner join NAMES_TABLE sn1 on sn1.ID = s1.ID_2
    where
      n1.NAME = :NAME
    union
    select
      sn2.NAME
    from
      NAMES_TABLE n2
      inner join SYNONYMS_TABLE s2 on s2.ID_2 = n2.ID
      inner join NAMES_TABLE sn2 on sn2.ID = s2.ID_1
    where
      n2.NAME = :NAME
    

    Note ID_2 and ID_1 being reversed in the second part of the second query.

    Which one you need, depends on the data. If you want ‘lane’ to be a synonym for ‘road’, but not the other way around, you should use the first method. But in that case you’ll have to remember that synonyms in both directions should be added twice, so you’ll get:

    NAMES_TABLE           SYNONYMS_TABLE
    ------------          --------------
    ID | NAME              ID_1 | ID_2
    ---+--------          ------+-------
    1  | Road              1  |  3
    2  | Lane              3  |  1
    3  | Street            2  |  1
    

    Now Road and Street are each others synonyms, but while Lane is a synonym for Road, Road is not for Lane.
    If you don’t want that behavour, you’d better use the second, although you may risk entering double records by swapping ID_1 and ID_2. You should be able to prevent this by checking that ID_2 is always higher than ID_1, never the same or lower.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need make a merge sort using an additional array. Here is my code:
We need to make our enterprise ASP.NET/NHibernate browser-based application able to function when connected
Need to make a function that would open a popout with a div inheriting
I need make a class, let's say FineStack , who should declare a structure
I need to make a lot of operations using BigDecimal, and I found having
I need to make a list/view (with several columns) like... Name Age Gender ---------------------
I need make UIAlertView blocking. Because i have function and i need to return
I need to make a program that adds long integers without using the biginteger
I have a crystal report file I need make a tiny edit in. It
I need to make a WebCast presentation soon and need to do some whiteboarding

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.