Created
August 14, 2014 21:05
-
-
Save betweenbrain/7a2c2abfecd7fee3d963 to your computer and use it in GitHub Desktop.
MySQL Join with Subquery Selecting Joined Data from Last Month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
table1.id, | |
table1.firstName, | |
table1.lastName, | |
a.sales | |
FROM `table1` | |
LEFT JOIN | |
( SELECT | |
firstName, | |
sales, | |
date | |
FROM `table2` WHERE MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH) | |
) as a | |
ON table1.firstName = a.firstName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment