Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. SELECT
  2. species.id
  3. FROM
  4. encyclopedia.species
  5. JOIN
  6. encyclopedia.common_names ON (common_names.owner_id = species.id AND common_names.owner_type = 'Species')
  7. WHERE
  8. species.name ILIKE E'%gavia%' OR common_names.name ILIKE E'%gavia%'
  9. GROUP BY
  10. species.id
  11. ORDER BY
  12. COALESCE(common_names.name, species.name);
Add Comment
Please, Sign In to add comment