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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:38:04+00:00 2026-05-28T19:38:04+00:00

In MySQL: If we have two tables: comments key | value ================= 1 |

  • 0

In MySQL:

If we have two tables:

comments
key    |    value
=================
1      |    foo
2      |    bar
3      |    foobar
4      |    barfoo

and:

meta
comment_key    |    value
=========================
1              |    1
2              |    1
3              |    2
4              |    1

I want to get the comments from the comment table that have a corresponding comment_key in the meta table that have a specific value (the value column in the meta table).

For example, I’d like to select all the rows from the comment table that have a value of 1 in the meta table:

I’d expect these results:

key    |    value
=================
1      |    foo
2      |    bar
4      |    barfoo

And if I were to select all the rows from the comment table that have a value of 2 in the meta table:

I’d expect this result:

key    |    value
=================
3      |    foobar

I really hope someone can help, thank you all in advance!

I think I need to do a join? Any pointers would be great, and if at all possible, a short explanation so I can work out where I was going wrong -> so I’ll know for next time!

  • 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-28T19:38:06+00:00Added an answer on May 28, 2026 at 7:38 pm

    I actually wouldn’t recommend a JOIN for this — or rather, I’d recommend a “semijoin“, which is a relational-algebra concept not directly expressed in SQL. A semijoin is essentially a join where you want to retrieve records from only one table, but with the proviso that they have corresponding records in a different table.

    In SQL notation, this concept is expressed indirectly, by using an IN clause, with a subquery:

    SELECT key, value
      FROM comments
     WHERE key IN
            ( SELECT comment_key
                FROM meta
               WHERE value = 1
            )
    ;
    

    (MySQL will actually end up translating that back into a semijoin internally — essentially a sort of degenerate inner-join — but the IN clause is the natural way to express it in raw SQL.)

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

Sidebar

Related Questions

I have two MySQL (MyISAM) tables: Posts: PostID(primary key), post_text, post_date, etc. Comments: CommentID(primary
I have two MySQL tables, and I want to find and replace text strings
I have two mysql tables and i want to merge the results of these
I have two tables in MySql Company : (cname,city) works : (ename,cname,salary) I want
using php and mysql I have two tables, a users table and a profiles
I have two mysql tables, one containing details on cars and one containing all
I have two tables in a MySql DB: items id (char) name (varchar) description
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever
I am newbee with PHP and MySQL and need help... I have two tables
I have two different tables, lead and click. I would like to query MySQL

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.