sql - Combine two SELECT queries in PostgreSQL -
i combine 2 select queries union.
how can use result first select in second select?
(select carto_id_key table1 tag_id = 16) union (select * table2 carto_id_key = <the carto_id result above> )
use cte reuse result subquery in more 1 select.
need postgresql 8.4+ that:
with x (select carto_id_key table1 tag_id = 16) select carto_id_key x union select t2.some_other_id_key x join table2 t2 on t2.carto_id_key = x.carto_id_key you want union all instead of union. doesn't exclude duplicates , faster way.
Comments
Post a Comment