Created
May 8, 2018 09:21
-
-
Save Pomeha/505e88d8070d7688ef72a1558f4ad541 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
ApplicationRecord.connection.execute('SELECT clients.*, | |
(CASE WHEN agents_clients.id is NULL then 0 else 1 END) | |
AS joined FROM clients | |
LEFT JOIN agents_clients | |
on clients.id = agents_clients.client_id | |
INNER JOIN users ON users.id = clients.user_id | |
WHERE agents_clients.id is NULL OR agents_clients.agent_id = 4 | |
ORDER BY joined, users.name' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment