Created
September 6, 2009 22:18
-
-
Save hakanensari/182017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Following works with PostgreSQL when I want to SELECT DISTINCT | |
# and ORDER BY a field but use another if the first is NULL. | |
has_many :things, | |
:through => :hashtags, | |
:select => "DISTINCT things.*, CASE WHEN things.completed_at IS NOT NULL THEN things.completed_at ELSE things.created_at END AS created_or_completed_at", | |
:order => "created_or_completed_at DESC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment