Search code examples
sqluniqueconstruct

Re-writing without using unique construct in SQL


Using the schemas member(memb_no, name, age), book(isbn, title, authors, publisher), and borrowed(memb_no, isbn, date), I have the following query. Only problem is I'm not supposed to use the unique construct. How can I re-write this without using the unique construct?

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);

Solution

  • You've already got other valid answers, but my preferred form would be:

    Select T.course_id 
    From course as T 
    Where (Select Count(*)
           From section as R 
           Where T.course_id = R.course_id and R.year = 2009) = 1;