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

  • SEARCH
  • Home
  • 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 328719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:31:17+00:00 2026-05-12T09:31:17+00:00

i have two tables in my database one is A other one is B

  • 0

i have two tables in my database one is A other one is B
A is having few fields in which three are id,name,group
B is having feilds like id,title,description, etc.

i have to search the id’s of title and description that are having data similar to table A’s name or group and then have to insert the id’s in a field of table A.

For example,
if A is having ‘Anna’ in its name and ‘girl’ in its group then i have to search the title’s and descriptions in table B that are containing this word ‘Anna’ or ‘girl’.

I want to do this in one single query.

How can i do so?

Edit:
Iam explainng my tables here for a better understanding

 table A

id     name     group     matched_id
1       anna     girl
2       sydney   girl
3        max      boy                             etc.

Table B

id      title                                      description
1       A good girl                             Anna is a very good girl
2      Max doesnt work hard                    Boys are always like that only

etc…

see i will first search for a match for ‘anna’ in the table B’s title and description and if a match is found in either of them then i’ll store that id in table A only in the field ‘matched id’
I’ll do the same procedure for ‘girl’ and then for ‘sydney’ and so on

  • 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-12T09:31:17+00:00Added an answer on May 12, 2026 at 9:31 am

    This query should do the trick:

    UPDATE a SET matched_id =
     (SELECT b.id FROM b
      WHERE b.title LIKE CONCAT(' % ',a.name,' % ')
      OR b.description LIKE CONCAT('% ',a.name,' %')
      OR b.title LIKE CONCAT('%',a.group,'%')
      OR b.description LIKE CONCAT('%',a.group,'%')
      LIMIT 1)
    WHERE EXISTS
     (SELECT a.id FROM b
      WHERE b.title LIKE CONCAT('% ',a.name,' %')
      OR b.description LIKE CONCAT('% ',a.name,' %')
      OR b.title LIKE CONCAT('%',a.group,'%')
      OR b.description LIKE CONCAT('%',a.group,'%')
      LIMIT 1)
    

    Some remarks to this:

    • LIMIT 1 was necessary, as each subquery can and will return more than 1 row
    • Not 100% sure if the order you want/need is used, you may need some further testing for that and use order by if needed
    • it may also be better to use an extra table for the groups (to reduce duplicate entries) and maybe one extra mapping table, so that you can map all results from B to A

    EDIT:
    if names need to match perfectly (unlike girl/girls), you can just add a space in front of the name: ‘% ‘,a.name,’ %’. If it gets more complicated I would suggest using regular expressions (REGEX). I modified the query with the spaces (for names only), so feel free to try it again.

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

Sidebar

Related Questions

I have two related tables in my database: Page and Tag. One Page can
I have two tables in my database schema that represent an entity having a
I have two tables: one hostgroup_host and the other one hostgroups. The hostgroups represents
I have two sql files: The first one creates database, tables, and stored procedures.
I have a database with three tables, one with titles, one with authors and
I have two database tables, one in MYSQL and one in MSSQL. Both have
The database I am working with currently does have two tables, one holding the
I have a table and two databases which have the same table, but one
I have two database tables with the following structure: actions: action_id int(11) primary key
I have two tables in my database, called ratings and movies . Ratings: |

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.