Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created August 14, 2014 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betweenbrain/b0027305656e44fe882e to your computer and use it in GitHub Desktop.
Save betweenbrain/b0027305656e44fe882e to your computer and use it in GitHub Desktop.
Simple MySQL Join with Last Month Where Clause
SELECT
table1.id,
table1.firstName,
table1.lastName,
table2.sales,
table2.date
FROM `table1`
LEFT JOIN `table2` ON table1.firstName = table2.firstName
WHERE MONTH(table2.date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment