Skip to content
Advertisement

How to query and obtain a result set containing at minimum the SET of values submitted

The code I provided simply contains three fake lists. Each list contains a set of values. How do I write a query that gives me all the records in the list that contain the values I specify. Using an IN statement doesn’t work as it gives me ALL the lists(records) that contain those list values. Instead I need returned only the list records that contain at least all of the values I specified.

In my example since I provided four values (‘A’,’B’,’C’,’D’) I should only see in my result set the records for the first list with lookupID 1001. If for example I submit a single value of ‘A’ I would then see all of the Records for List 1001 and List 1002 as both of those lists contain at minimum the value ‘A’. List 1003 does not have any values of ‘A’.

Advertisement

Answer

You get the lookupIDs that you want with this query:

and all the rows of the table with the use of the operator IN:

The code is standard SQL and works in any database (that I know of).
See the demo.
Results:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement