SQL (weight: 10%) Consider the table below: table A ( id integer primary key, name varchar(20), age integer ) Write a query to return the list of unique names from table A
Sigiloso
We cant use DISTINCT here. As the question asks for the Unique names to return, which means names that are not duplicated in the table, we have to return the names that the count of that name in the table is 1. SELECT name FROM TableA t1 WHERE ( SELECT COUNT( name ) FROM TableA t2 WHERE t1.name = t2.name ) = 1; id name age 1 Test1 2 2 Test2 0 3 Test1 4 4 Test3 5 5 Test4 5 6 Test2 5 In the above table you will get the result Test3 and Test4 as those 2 are the only Unique names in the table. all the other names are duplicated.