E
E
estry2022-04-18 16:21:42
PostgreSQL
estry, 2022-04-18 16:21:42

How to write a sql query to get the same data?

Hello.
There is a table in the database like this:
625d6486c20f3787157940.png
I need to make a request by specifying id to get data, and if there is duplicate data in id_input, then get them.
For clarity, I'll show you a picture. Sending a request specifying id 1001, I expect to receive the following data
625d652e1e25e208251759.png

. I try to send such a request, but there is no result

SELECT id, id_input, id_out
FROM data
WHERE id= 1001
GROUP BY id
HAVING COUNT(DISTINCT id_input)>1


What needs to be added to the request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-04-18
@Akela_wolf

It is possible through JOIN:

SELECT t2.* FROM t t1 JOIN t t2 ON t1.input_id = t2.input_id
WHERE t1.id=1

Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question