Skip to content

Instantly share code, notes, and snippets.

@hunterloftis
Created August 12, 2012 18:35
Show Gist options
  • Save hunterloftis/3333630 to your computer and use it in GitHub Desktop.
Save hunterloftis/3333630 to your computer and use it in GitHub Desktop.
Attempted CASE query
-- Doesn't work (returns affiliation = null):
SELECT dating.*,
CASE WHEN dating.traditional = choices.id AND choices.cat = 'trad' THEN choices.choice END as affiliation
FROM dating, choices
LIMIT 1
-- Works:
SELECT dating.*, choices.choice as affiliation
FROM dating, choices
WHERE dating.traditional = choices.id AND choices.cat = "trad"
LIMIT 1
-- Does return something:
SELECT dating.*,
CASE WHEN true THEN choices.choice END as affiliation
FROM dating, choices
LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment