Union within a Where statement not working

Hi there, on exercise https://www.codecademy.com/paths/data-science/tracks/sql-intermediate/modules/dspath-sql-multiple-tables/projects/querying-tables
bonus question 8,

"REBU is looking to do an email campaign for all the irregular users.

Find all the riders who have used REBU less than 500 times!"

are the instructions.

I coded:


WHERE total_riders AS(

  SELECT * FROM riders

  UNION

  SELECT * FROM riders2

)

SELECT first, last, username

FROM total_riders

WHERE total_trips < 500;

my thought process being that there are two tables of riders: riders, and riders2. So I used union to create a new dataset, and then I wanted to query that combined dataset for all riders that have taken less than 500 rides. When I hit save, nothing appears. No error message, just nothing. I looked at the intended solution, which is simply to do a union query of all rows from both tables, but what I really want to know is why my query didn’t work, and how to actually accomplish what I was trying to do.

Your thought process seems right, it’s just a very minor error (WHERE instead of WITH) combined with the lack of error message that seems to be your issue.

2 Likes

HA, it would be something silly like that. Thanks.

1 Like