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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:15:32+00:00 2026-05-19T14:15:32+00:00

I have a couple tables that look like this: ___________ ___________ | Books |

  • 0

I have a couple tables that look like this:

 ___________    ___________
| Books     |  | Tags      |
|-----------|  |-----------|
| book_id   |  | tag_id    |
| book_name |  | tag_name  |
 -----------    ----------- 

And a join table that connects the “many-to-many relationship”:

 ___________
| Books/Tags|
|-----------|
| book_id   |
| tag_id    |
 -----------

I want to do a query that’s kind of like this:

SELECT book_name, tag_name FROM books, tags WHERE tag_name = 'fiction'

Is there any way to “attach” the books table to the tags in the query since they have a join table between them? Or do I have to do three queries, one to get the tag_id, another to get the book_id matching the tag_id, and a third to get the book_name matching the tag_id?

  • 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-19T14:15:33+00:00Added an answer on May 19, 2026 at 2:15 pm

    Yes you can do; with a JOIN:

    SELECT b.book_name, t.tag_name FROM books b
    JOIN books_tags bt ON bt.book_id=b.book_id
    JOIN tags t ON t.tag_id=bt.tag_id
    WHERE t.tag_name = 'fiction';
    

    This will return a list of books which have the ‘fiction’ tag.

    Alternatively you can do it with subqueries:

    SELECT b.book_name FROM books b WHERE id IN (
        SELECT bt.book_id FROM books_tags bt
        WHERE bt.tag_id IN (
            SELECT t.tag_id FROM tags t WHERE t.tag_name='fiction'
        )
    )
    

    Or:

    SELECT b.book_name FROM books b WHERE EXISTS (
        SELECT 1 FROM books_tags bt
        JOIN tags t ON t.tag_id=bt.tag_id
        WHERE t.tag_name='fiction'
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple tables that look like this: ___________ ___________ | Books |
I have a couple of tables which look like this Table 1 user_id |
I have a couple of POCO objects that look like this: public abstract class
I have a couple of very large tables (over 400,000 rows) that look like
I have a couple of tables that are transaction tables, and I would like
I have a couple of tables (mySQL) that i would like to update with
I have a couple of tables with similar structures like this: <table> <tbody> <tr>content</tr>
I have a couple of tables that i join together when i execute the
I have couple of statements, the pseudo code would look something like this: insert
I have a couple of tables that need to be be joined. The tables

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.