Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases

Gurdeep singh
Gurdeep singh
1,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;

1 Answer

Steven Parker
Steven Parker
216,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.

Gurdeep singh
Gurdeep singh
1,522 Points

Yes I need a count thank you I am really stuck on this and also on this topic