there is a table -
table_a
| id | name | price |
and such a request -
(select id, name, price from table_a where to_tsvector('russian', name) @@ plainto_tsquery('russian', 'винт') order by price asc limit 1) union all (select id, name, price from table_a where to_tsvector('russian', name) @@ plainto_tsquery('russian', 'гайка') order by price asc limit 1) Actually, it searches for fts names and gives it with the lowest price. Each item in the request.
http://sqlfiddle.com/#!15/eaa2b/24
Is there any way to get rid of union all ? And how will this all be if there are many associations?
Or is it easier to just do it on request and then combine the result for example php ?
JOINto thetsqueryset, recorded viaVALUESaccording to the predicate with@@, and ensure uniqueness with the help ofDISTINCT ONto thesetsquery. And if you set the order by price, then one entry will be selected for eachtsquerywith the minimum price. I dare not write this to SQL ._. And I strongly suspect that this will not win before individual requests. - D-side