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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:56:09+00:00 2026-06-12T08:56:09+00:00

With the following simple table structure: Data ———- id Tag ———- id TaggedData ———-

  • 0

With the following simple table structure:

Data
----------
id

Tag
----------
id

TaggedData
----------
id
tag_id
data_id

If I had a list of Tag ids, how would I fetch every row of Data where every row of Tag in my list has a relation to a row of Data matched and not a subset thereof?

Here’s the query I have right now that doesn’t work:

    SELECT
        Data.*

    FROM
        Data
    LEFT JOIN
        TaggedData ON (Data.id = TaggedData.data_id)
    LEFT JOIN
        Tag ON (Tag.id = TaggedData.tag_id)

    WHERE
        Tag.id IN ('1' , '2')

Specifically: This one isn’t working because it will return any row of Data that is related to Tag 1 or 2. Not 1 and 2.

  • 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-12T08:56:10+00:00Added an answer on June 12, 2026 at 8:56 am

    This is called “relational division”

       SELECT 
            Data.ID  
        FROM 
            Data 
        INNER JOIN 
            TaggedData ON (Data.id = TaggedData.data_id) 
        INNER JOIN 
            Tag ON (Tag.id = TaggedData.tag_id) 
        WHERE 
            Tag.id IN ('1' , '2') 
        HAVING COUNT(DISTINCT tag.iD)=2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a simple table with the following data: id | result | played ----+--------+------------
With a table of the following structure and sample data: TableActivity ------------- Type VARCHAR(8)
I'm using a MySql table with the following simple structure : ID_A : int
Let's say I have the following hypothetical data structure: create table country ( country_id
Possible Duplicate: sql query to sum the data I have following table structure TradeId
I'm using Hibernate 3.3.1 and am following along in modelling this sample table structure
I have the following task: there are a simple table from mysql database: <html>
I have a very simple table called Member , which consists of the following:
I am trying to make a JQGrid for a simple table. After following through
i m having following type of simple sql server table Here I want to

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.