Skip to content
Advertisement

Joining two queries with different where clauses into 1 table

This is probably a pretty simple question, but I have two separate queries that I would like to join into one table. One of the queries shows sign ups to my website by month and the other query shows sign ups that have made a purchase. I would like to combine the two queries into one table so I have the following table:

How can I do that? Here’s my two queries:

Sign ups:

Sign ups with purchase:

thank you!

Advertisement

Answer

I think that you can just add a count(distinct u.id) to the second query:

Note: I changed your right join to a left join; most people tend to consider that right joins are rather counter-intuitive, and favor left joins instead.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement