Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Bruce McMinn
Bruce McMinn
10,030 Points

Subqueries Review & Practice # 1 Clunky Answer

So question 1 asks for a list of all titles and a count of duplicate books. That sounds like a column of words and another column with a single numeric entry. Can I combine these two making a derived table of either?

-- a list of all books, no duplicate titles

SELECT bn.title FROM books_north AS bn
EXCEPT
SELECT bs.title FROM books_south AS bs
UNION
SELECT bs.title FROM books_south AS bs;

and

-- a complicated way to get the number 12

SELECT COUNT(*) AS BooksWithMultipleCopies FROM 
(SELECT COUNT(*) as book_num
FROM (SELECT title FROM books_north 
      UNION ALL
      SELECT title FROM books_south)    
GROUP BY title
HAVING book_num>1);

I'm guessing that there isn't a good join criteria??

Steven Parker
Steven Parker
229,785 Points

Actually it sounds like it could be done easily with a join. Could you share a link to the course page so the original instructions can be viewed?

Bruce McMinn
Bruce McMinn
10,030 Points

Sure thing Steven, thanks for your help.

The link to the database is: https://teamtreehouse.com/sql_playgrounds/522#/queries/670ffc6e-68f8-4117-aeda-a3bd5d37d4b3

and it is at: Databases/Querying Relational Databases/Subqueries/Review and Practice.

Do you know how I get a question's subject that specific when I ask it? As in page view