Skip to content

Instantly share code, notes, and snippets.

@btc

btc/-

Created July 6, 2014 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btc/9ce058c990511c15b2c6 to your computer and use it in GitHub Desktop.
Save btc/9ce058c990511c15b2c6 to your computer and use it in GitHub Desktop.
SELECT targets.id, targets.name, traits.id, traits.name
FROM Traits INNER JOIN People AS targets ON
targets.id != me
LEFT OUTER JOIN Opinions AS ops ON
ops.person_id = me AND
ops.trait_id = traits.id AND
ops.about_id = targets.id
GROUP BY targets.id, traits.id
HAVING(MAX(ops.update_at)
WHERE ops.rating IS NULL
ORDER BY targets.name, traits.name
LEFT OUTER JOIN skips ON
skips.from_id = me AND
skips.about_id = targets.id AND
skips.trait_id
WHERE skips.id IS NULL
ActiveRecord::Base.connection.execute(“SELECT targets.id, targets.name, traits.id, traits.name FROM Traits INNER JOIN People AS targets LEFT OUTER JOIN Opinions AS ops ON ops.person_id = 7 AND ops.trait_id = traits.id AND ops.about_id = targets.id WHERE ops.rating IS NULL GROUP BY targets.id, traits.id HAVING(MAX(ops.update_at)) ORDER BY targets.name, traits.name”)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment