Choose different from other selection results

I want to select different results from other select query results for example;

select distinct from(select * from table)

Below is the result of internal selection

testing department      9998901036      GOLD    
testing department      9998901036      GOLD

I want to get a great result.

+3
source share
2 answers

In your example, you can just do

select distinct * from table

But say that you had some kind of scenario in which you would like to distinguish some other results, you could do

select distinct column1, column2 from (select * from table) T

Please note that you must use your internal choices.

+9
source
select distinct * 
from
(select * from table) t

Work. You just need to let your selection select a table alias.

You can also use CTE.

;WITH t AS
(
SELECT * 
FROM table
)
SELECT DISTINCT * 
FROM t
+1
source

All Articles