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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:46:12+00:00 2026-06-08T12:46:12+00:00

I am representing itemsets in SQL (SQLite, if relevant). My tables look like this:

  • 0

I am representing itemsets in SQL (SQLite, if relevant). My tables look like this:

ITEMS table:

| ItemId | Name    |
| 1      | Ginseng |
| 2      | Honey   |
| 3      | Garlic  |

ITEMSETS:

| ItemSetId | Name                |
| ...       | ...                 |
| 7         | GinsengHoney        |
| 8         | HoneyGarlicGinseng  |
| 9         | Garlic              |

ITEMSETS2ITEMS

| ItemsetId | ItemId |
| ...       | ....   |
| 7         | 1      |
| 7         | 2      |
| 8         | 2      |
| 8         | 1      |
| 8         | 3      |

As you can see, an Itemset may contain several Items, and this relationship is detailed in the Itemset2Items table.

How can I check whether a new itemset is already in the table, and if so, find its ID?

For instance, I want to check whether “Ginseng, Garlic, Honey” is an existing itemset. The desired answer would be “Yes”, because there exists a single ItemsetId which contains exactly these three IDs. Note that the set is unordered: a query for “Honey, Garlic, Ginseng” should behave identically.

How can I do this?

  • 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-08T12:46:14+00:00Added an answer on June 8, 2026 at 12:46 pm

    I would recommend that you start by placing the item sets that you want to check into a table, with one row per item.

    The question is now about the overlap of this “proposed” item set to other itemsets. The following query provides the answer:

    select itemsetid,
    from (select coalesce(ps.itemid, is2i.itemid) as itemid, is2i.itemsetid,
                 max(case when ps.itemid is not null then 1 else 0 end) as inProposed,
                 max(case when is2i.itemid is not null then 1 else 0 end) as inItemset
          from ProposedSet ps full outer join
               ItemSets2items is2i
               on ps.itemid = is2i.itemid
          group by coalesce(ps.itemid, is2i.itemid), is2i.itemsetid
         ) t
    group by itemsetid
    having min(inProposed) = 1 and min(inItemSet) = 1
    

    This joins all the proposed items with all the itemsets. It then groups by the items in each item set, giving a flag as to whether the item is in the set. Finally, it checks that all items in an item set are in both.

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

Sidebar

Related Questions

8 bits representing the number 7 look like this: 00000111 Three bits are set.
I have a few checkboxes representing people. Something like this: [ ] George [
I have a table representing values of source file metrics across project revisions, like
I have a listbox representing a SQL WHERE statement and the items inside can
I have an entity representing Documents that looks like this: Document date_creation doc_number doc_origin
I have 3d-data representing the atmosphere. Now I want to interpolate this data to
I have a string representing a SQL query, and I need to extract the
I have string data representing locales, like fr or en. I need to convert
I have a string representing a path. Because this application is used on Windows,
I have a table representing users. When a user is deleted I get: DELETE

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.