开发者

Select distinct from another select results

I want to select distinct results from another select statement results e.g;

select distinct from(select * from table)

following is result of inner select

testing department      9998901036      GOLD    
testing department      9998901036      GOLD

I want to get 开发者_如何学Cdistinct from above select result.


From your example, you could just do

select distinct * from table

But say you had some scenario where you wanted to distinct on some other results set, you could do

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

Note that you have to alias your inner select


select distinct * 
from
(select * from table) t

Works - You just need to give your sub select a table alias.

You can also use a CTE.

;WITH t AS
(
SELECT * 
FROM table
)
SELECT DISTINCT * 
FROM t
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜