Skip to content

Instantly share code, notes, and snippets.

@tlkshadow
Last active April 24, 2017 07:42
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 tlkshadow/e9bac12e91ac48f21054d44e05925615 to your computer and use it in GitHub Desktop.
Save tlkshadow/e9bac12e91ac48f21054d44e05925615 to your computer and use it in GitHub Desktop.
Bad example
SELECT 
 a.id
 b.name,
 s.name,
 s.address,
 max(ap.price) as newest_price,
 wm.quantity
 #— ….
FROM article a 
JOIN brand b on a.brand_id = b.id
LEFT JOIN supplier s ON s.id = a.supplier_id
LEFT JOIN article_price ap ON ap.article_id = a.id 
GROUP BY a.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment