Smiley Smiley - 5 months ago 11
SQL Question

SQL Select row from a table which has a link with every possible value that exists in a column in another Table

I have something like this two tables:

A
____
| ID |
|----|
| 1 |
| 2 |
----

B
____ ______
| ID | TYPE |
|----|------|
| 1 | Q |
| 2 | W |
| 1 | W |
---- ------


Here i want to return 1 from table A cause it's linked with all possible types that exist in table B.

EDIT:
I don't know before the query what all possible types are

Answer

You can always try this:

select id
  from b
 group by id
having count(distinct type) = (select count(distinct type) from b)
Comments