Answer the question
In order to leave comments, you need to log in
What is the best way to write SELECT for product translations?
there is a table product
and product_translate
for one product there are translations in several languages,
we need to select a language that the user understands better (there is one id
) if there is no such translation, then we select any other
, this is all in one query
, how best to write? product_translate
:
you can use subqueries, but you will have to write 2 subqueries, 1 for title
, 2 for description
and it's still not clear how to write ORDER BY
in subqueries
Answer the question
In order to leave comments, you need to log in
select ...
from product as p
join lateral (
select title, description from product_translate as pt
where pt.product_id = p.id order by language_id = ? limit 1
) on true
where ....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question