Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Last active April 16, 2020 18:01
Show Gist options
  • Save sonOfRa/fb21e81f8a5ce2881cbf6dea8b9fc0b0 to your computer and use it in GitHub Desktop.
Save sonOfRa/fb21e81f8a5ce2881cbf6dea8b9fc0b0 to your computer and use it in GitHub Desktop.
SELECT *
FROM (SELECT DISTINCT ON (id) id.description AS description,
id.name AS name,
itn.name AS typename,
itn.ingredient_type_id AS typeid,
l.language AS language,
l.country AS country,
ingredient.id AS id
FROM ingredient
JOIN ingredient_data id ON ingredient.id = id.ingredient_id
JOIN language l ON id.language_language = l.language AND id.language_country = l.country
JOIN ingredient_type_name itn
ON id.language_language = itn.language_language AND id.language_country = itn.language_country AND
itn.ingredient_type_id = ingredient.ingredient_type_id
WHERE ((l.language LIKE 'de' AND l.country LIKE 'AT') OR
(l.language LIKE 'de') OR
(l.language LIKE 'zzzzzzzzzz' AND l.country LIKE 'zzzzzzzzzz'))
ORDER BY id, language) AS derived
ORDER BY name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment