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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:27:34+00:00 2026-06-09T01:27:34+00:00

I have two tables as follows: CREATE List ( id INTEGER, type INTEGER REFERENCES

  • 0

I have two tables as follows:

CREATE List (
    id   INTEGER,
    type INTEGER REFERENCES Types(id),
    data TEXT,
    PRIMARY_KEY(id, type)
);

CREATE Types (
    id   INTEGER PRIMARY KEY,
    name TEXT
);

Now I want to create a query that determines all ids of List which has given type strings.

For example,

List:
1    0    "Some text"
1    1    "Moar text"
2    0    "Foo"
3    1    "Bar"
3    2    "BarBaz"
4    0    "Baz"
4    1    "FooBar"
4    2    "FooBarBaz"

Types:
0    "Key1"
1    "Key2"
2    "Key3"

Given the input “Key1”, “Key2”, the query should return 1, 4.

Given the input “Key2”, “Key3”, the query should return 3, 4.

Given the input “Key2”, the query should return 1, 3, 4.

Thanks!

  • 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-09T01:27:35+00:00Added an answer on June 9, 2026 at 1:27 am
    select distinct l.id 
    from list l
    inner join types t on t.id = l.type
    where t.name in ('key1', 'key2')
    group by l.id
    having count(distinct t.id) = 2
    

    You have to adjust the having clause to the number of keys you are putting in your where clause. Example for just one key:

    select distinct l.id 
    from list l
    inner join types t on t.id = l.type
    where t.name in ('key2')
    group by l.id
    having count(distinct t.id) = 1
    

    SQlFiddle example

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

Sidebar

Related Questions

I have two MySQL tables structed as follows; advert +-------------------+--------------+ | Field | Type
I have two tables as follows: CREATE TABLE customer ( id INT NOT NULL
I have two tables as follows: tblCountry (countryID, countryCode) tblProjectCountry(ProjectID, countryID) The tblCountry table
I have two tables as follows.. campaigns(campaignID, title) campaignMailList(campaignID, Sent) (The 2 tables are
I'm using PHP/MySql. If I have two tables (hypothetically) as follows: id name and
If I have two tables - Logins and Users, as follows: Logins LoginIdNo UserIdNo
I have two tables as follows: TableOne - RawDataId int (pk) - TimeStamp DateTime
I have two large tables, as follows: First Table: tbl_properties id address city state
We have two tables resembling a simple tag-record structure as follows (in reality it's
I have two tables, a destination for the update: create table dest (value int)

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.