R
R
Ragivort2019-12-06 10:42:14
PostgreSQL
Ragivort, 2019-12-06 10:42:14

Query on two PostgreSQL tables?

Hello, help me to correctly form the request, something is confused.
There is a Field - an identifier in one table, there is another table in which the same identifiers (Users) may be present.
A query is needed that will display the user if he is in the first table, or in the second table + another condition for the second table, for example is_active.
The second table may contain several entries for this user.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Melnikov, 2019-12-06
@immelnikoff

SELECT `id` FROM `t1` UNION SELECT `id` FROM `t2` WHERE `is_active` = 1

S
Sergey c0re, 2019-12-07
@erge

SELECT id FROM (
  SELECT id FROM tbl1
  UNION
  SELECT id FROM tbl2 WHERE is_active = 1
) WHERE id = SOME_ID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question