remove duplicates from sql union

后端 未结 6 560
北恋
北恋 2020-12-29 01:45

I\'m doing some basic sql on a few tables I have, using a union(rightly or wrongly)

but I need remove the duplicates. Any ideas?

select * from calls
         


        
6条回答
  •  悲&欢浪女
    2020-12-29 02:23

    If you are using T-SQL then it appears from previous posts that UNION removes duplicates. But if you are not, you could use distinct. This doesn't quite feel right to me either but it could get you the result you are looking for

    SELECT DISTINCT *
    FROM
    (
    select * from calls
    left join users a on calls.assigned_to= a.user_id
    where a.dept = 4 
    union
    select * from calls
    left join users r on calls.requestor_id= r.user_id
    where r.dept = 4
    )a
    

提交回复
热议问题