Consider a table
results (id, key, value) where key is the Primary key.
Sample data:
id | key | value
-----------------------
abc| source-1 | 20
abc| source-2 | 30
abc| source-3 | 2
abc| source-4 | 10
def| source-5 | 1
ghi| source-6 | 25
jkl| source-5 | 13
I would like to return only those records which have a single entry for a given id. So output should be
id | key | value
------------------------
def| source-5 | 1
ghi| source-6 | 25
jkl| source-5 | 13
Please advise.
One way is to use GROUP BY and HAVING to produce a derived table with the desired
ids and then JOIN to it:You could also use an IN if you don’t like derived tables: