Skip to content

Instantly share code, notes, and snippets.

@jhesyong
Created August 12, 2015 03:52
Show Gist options
  • Save jhesyong/47c9bdf8097f33215a66 to your computer and use it in GitHub Desktop.
Save jhesyong/47c9bdf8097f33215a66 to your computer and use it in GitHub Desktop.
Put null to the last when using left join
SELECT * FROM media
LEFT JOIN media_priority
ON (media_priority.media_id = media.id AND media_priority.media_tag = '".$tag."')
WHERE something = 'something'
ORDER BY (media_priority.media_order IS NULL) ASC, media_priority.media_order ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment