Skip to content

Instantly share code, notes, and snippets.

@thomsbg
Created October 29, 2013 15:04
Show Gist options
  • Save thomsbg/7216377 to your computer and use it in GitHub Desktop.
Save thomsbg/7216377 to your computer and use it in GitHub Desktop.
Left outer join + if statement
select stuff.*, if(
exchange_rate.rate is null,
(select rate from exchange_rates order by month desc limit 1),
exchange_rate.rate
)
from stuff
left outer join exchange_rate on exchange_rate.stuff_id = stuff.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment