Test for the absence of duplicate tuples

Asked

Viewed 25 times

2

I saw in a SQL book the following query:

select T.course_id from course as T where unique (select R.course_id from section as R where T.course_id = R.course_id and R.year = 2009)

I am unable to apply this query to SQL Server, which I put in place to replace Unique and return to subquery without duplicate tuples?

  • where unique is a syntax of Oracle, in the SQLServer use distict

  • But distinct doesn’t work after Where, only in select, so I don’t know how to apply this with a sub-query. I even put distinct in select but it doesn’t work.

  • yes, the distinct is used in the fields of select. See my answers

1 answer

1


This syntax is used in oracle, to the sql-server use distinct.
This subquery can be used with exists, since the distinct is part of the select, then the query would look like this:

select distinct T.course_id 
  from course as T 
 where exists (select R.course_id 
                 from section as R 
                where T.course_id = R.course_id and R.year = 2009)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.