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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:01:07+00:00 2026-06-03T07:01:07+00:00

There are 2 tables table1 table2 book_id | tag_id tag_id —————- ———– 5 |

  • 0

There are 2 tables

     table1                      table2

book_id | tag_id                 tag_id
----------------               -----------
  5     |   1                       1
  5     |   3                       3
  5     |   4                       4
  7     |   1
  7     |   2
  7     |   4

I need to create sql query for selection all book_id where tag_id is multitude of all tag_id from table2 (SQLite).

For example, book_id = 5 is acceptable because it has all tags from table2 (1, 3, 4).
The book with book_id = 7 isn’t acceptable because it has only 1 and 4 tags, but hasn’t tag_id = 3.

  • 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-06-03T07:01:09+00:00Added an answer on June 3, 2026 at 7:01 am

    I’m not sure if this query will be very efficient, but…

    select distinct book_id from table1 x 
    where not exists(
    select * from table2 t where not exists(
    select * from table1 a 
    where a.tag_id = t.tag_id 
    and a.book_id = x.book_id));
    

    Setup code:

    drop table table1;
    drop table table2;
    create table table1(book_id int, tag_id int);
    insert into table1 values(5, 1);
    insert into table1 values(5, 3);
    insert into table1 values(5, 4);
    insert into table1 values(7, 1);
    insert into table1 values(7, 2);
    insert into table1 values(7, 4);
    create table table2(tag_id int);
    insert into table2 values(1);
    insert into table2 values(3);
    insert into table2 values(4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Table1 and Table2 related on Table1.ID. There can be zero or more
There is a table: create table table1 ( id integer primary key, user_id varchar(36),
i need to do this : There is a table called table1 it has
i need to do this : There is a table called table1 it has
There are two tables, categories and books and I'd like to select all books
I just need a single MySQL line query for the following. Lets say there
I have EF 4 implemented in the project. Within it, there are tables customer
There are three tables in my database: apples, refrigerators, and houses. Each apple belongs
There are two tables. One is users info users, one is comments info comments.
I have a couple tables where there is a same field added . What

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.