Skip to content

Instantly share code, notes, and snippets.

@nhatnx
Last active December 25, 2017 05:15
Show Gist options
  • Select an option

  • Save nhatnx/4ddbd22f67f1229412cf1e38604eac3a to your computer and use it in GitHub Desktop.

Select an option

Save nhatnx/4ddbd22f67f1229412cf1e38604eac3a to your computer and use it in GitHub Desktop.
ORDER BY column which is a mixed of multi columns with some criteria
SELECT * FROM table
ORDER BY
CONCAT
(CASE WHEN (security_title_name IS NOT NULL AND security_title_name != '') AND (release_date IS NOT NULL AND release_date != '') AND (release_date > CURRENT_DATE) THEN security_title_name
ELSE official_title_name
END)
ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment