如何避免与sql查询中的所有字段重复值

时间:2015-05-14 08:02:19

标签: sql sql-server

我有这样的查询:

Select * from V_Receipt Where F_Exhibition='11000' order by F_Exhibitor_Name

执行时我得到重复的值,我该如何解决这个问题。

2 个答案:

答案 0 :(得分:1)

您需要使用DISTINCT,但您还必须明确定义每个字段

SELECT DISTINCT field1, field2, field3 /* etc etc */ 
FROM V_Receipt 
WHERE F_Exhibition = '11000' 
ORDER BY F_Exhibitor_Name DESC

答案 1 :(得分:-2)

with cte 
as
(select row_number(partition by feild 1 order by field1) as rnk,* from V_Receipt )
select * from cte where rnk=1;