I’ve got two tables
id | name
1 | foo
2 | foo
2 | foo <- duplicated id
3 | bar
and
id | value
1 | 100
1 | 200
2 | 300 <- same value and id
2 | 300 <-
3 | 500
I need to get the rows from the second table for each id with name foo:
1 100
1 200
2 300
2 300
The id/name table isn’t normalized and I can’t do anything about that. So I need to select the distinct ids from table 1 and non distinct id/values from table 2. Is there a way to do this?
You don’t specify which version of SQL you are using. The following should work with any version: