SQL Training Exercise Assistance [closed]

EDITED POST-ACLARATION:

First one, with exists:

SELECT title, subtitle
FROM book b
where exists (select bc.bookid, count(*)
                from book_copy bc 
                where bc.bookdescid = b.bookdescid
                group by bc.bookid
                having count(*) = 1);

Second with INNER JOIN:

 select b.bookid, count(*)
 FROM book b
    inner join book_copy bc on bc.bookdescid = b.bookdescid
 group by b.bookid
 having count(*) = 1;

if you need title and subtitle columns in the selected columns you could use an in:

 select title, subtitle
 from book
 where bookid in (select b.bookid
       FROM book b
          inner join book_copy bc on bc.bookdescid = b.bookdescid
       group by b.bookid
       having count(*) = 1)

And the final one with set operators:

SELECT b.bookid, 
FROM book b
EXCEPT
select b.bookid
       FROM book b
          inner join book_copy bc on bc.bookdescid = b.bookdescid
       group by b.bookid
       having count(*) > 1

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top