I have a table having details such that
Userpin product Time1 contains
4556 23 7:30 A
4557 23 7:30 B
4558 23 7:30 C
4559 23 7:30 D
4560 23 7:30 E
4561 24 7:30 A
4562 24 7:30 B
4563 24 7:30 C
4564 24 7:30 D
4565 24 7:30 E
4566 25 7:30 A
4567 25 7:30 A
4568 23 7:30 F
4568 23 7:30 G
So with the above table, I need all products that contains (A,B,C,D,E,F) all of them.
With the given table, I am expecting 23 as the result (Although product 23 contains G as well, but that does not bother me.).
Best Answer
I have recreated your table in tempdb using the Adventure Works Database. This code basically selects all the records that have column contains ('A', 'B', 'C', 'D', 'E', 'F') and then does a distinct count on the [contains] column. When the result is six the record must have a row of all of ('A', 'B', 'C', 'D', 'E', 'F').
This is the Microsoft SQL Server syntax.