Answer the question
In order to leave comments, you need to log in
How to make a query in JOIN?
Hello!
I use PostgreSQL. There is a request, it has a lot of conditions to change it too lazily, you need to add a condition, I wanted to add join neatly, here is the simplest example:
CREATE TABLE t1 (
id int
);
INSERT INTO t1 (id) VALUES (1);
INSERT INTO t1 (id) VALUES (2);
INSERT INTO t1 (id) VALUES (3);
CREATE TABLE t2 (
t1_id INT,
status INT
);
INSERT INTO t2 (t1_id, status) VALUES (1, 1);
INSERT INTO t2 (t1_id, status) VALUES (1, 1);
INSERT INTO t2 (t1_id, status) VALUES (1, 3);
SELECT t1.*
FROM t1
INNER JOIN t2 ON (t1.id = t2.t1_id AND t2.status = 1)
WHERE
id=1 OR id=2 OR id=3
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question