0 votes
1 view
in SQL by (20.3k points)

I thought these were synonymous, but I wrote the following in Microsoft SQL:

Select Unique col from 

(select col from table1 union select col from table2) alias

And it failed. Changing it to

Select Distinct col from 

 (select col from table1 union select col from table2) alias

fix it. Can someone explain?

1 Answer

0 votes
by (36.7k points)

SELECT UNIQUE is the old syntax, which is supported by Oracle's flavor of SQL. It is similar to SELECT DISTINCT.

Use SELECT DISTINCT because this is the standard SQL, and SELECT UNIQUE as it is non-standard

In database brands other than Oracle, SELECT UNIQUE may not be recognized at all.

...