Welcome to the Treehouse Community
Looking to learn something new?
Gurdeep singh1,522 Points
CAN WE USE JOINS IN SUBQUERY?
I Have a task to Generate a report that lists the book titles from both locations and count the total number of books with the same title.
Can we use union in subqureries SELECT * FROM books_north LEFT OUTER JOIN (LEFT OUTER JOIN loans_north ON books_north.id = loans_north.book_id UNION ALL SELECT * FROM books_south LEFT OUTER JOIN loans_south ON books_south.id = loans_south.book_id) AS t;
Steven Parker216,083 Points
Technically, a subquery is used in a WHERE clause and a derived table is used in a FROM clause. But sure, you can use UNIONs and JOINs in either of them.
However, if all you're interested in are the book titles, you can simply this query a good bit by not joining the "loans" table. And it sounds like you might need the COUNT function in there.