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 trialGeorgina Wise
1,774 PointsDoes a WHERE clause only appear at the end of a query or does it have to go both sides of the set function?
Hi All,
Following the videos on SET OPERATIONS, Andrew mentioned you should only need to put the WHERE or ORDER BY clause at the end of the query. However, in code challenge 2 the WHERE clause must appear on both sides of the set operator so am a little confused?
I thought the answer should look like this:
SELECT name FROM Fruit
UNION
SELECT name FROM Vegetable
WHERE Name BETWEEN 'A' AND 'L';
But the answer is:
SELECT name FROM Fruit
WHERE name BETWEEN 'A' AND 'L'
UNION
SELECT name FROM Vegetable
WHERE Name BETWEEN 'A' AND 'L';
1 Answer
Becky Hirsch
14,069 PointsFrom what I understand the WHERE needs to be in both but you only need to order it once (as with ORDER BY). I found this explanation at 3:25 in the video "Union Operations".I hope this helps!