4
Maybe that question has even been answered already, but I don’t know how to do it, and I fell into the typical XY problem.
I have a table that has several ids, and I need to search two id’s, 34 e 5.
In the above case, I created exactly what you will bring in my table, only I need you to only bring information when you have the two numbers 34 and 5 in the same transaction, not just one. So in this case the IN didn’t work.
Follows structure of the table:
CREATE TABLE IDS (
IDTRANSACTIONS INT,
IDSUBSTATUS INT
);
INSERT INTO IDS (IDTRANSACTIONS, IDSUBSTATUS)
VALUES (12548, 1),
(12548, 5),
(12548, 34),
(12548, 6),
(12548, 3),
(48754, 1),
(48754, 5),
(48754, 32),
(48754, 3),
(48754, 1),
(48754, 6)
And the select I’m making:
select * from ids where idsubstatus in (34,5)
and the result it is bringing:
IDTRANSACTIONS IDSUBSTATUS
12548 5
12548 34
48754 5
IDTRANSACTION 12548 is correct, but not 48754. :)
You want the
IDTRANSACTIONS
which has at least one line withIDSUBSTATUS
34 and another withIDSUBSTATUS
5? That?– Sorack
That’s right. You have to have both idsubstatus. The two lines (34 and 5) at the same time.
– Layla Comparin
@Laylacomparin You who return twice the
12548
or only once?– Roberto de Campos
The way it looks in the score, but since 48754 doesn’t have 34, I don’t want you to bring it. For me the important thing is to see the two lines in the same transaction (34 and 5). If only one line comes, in the case the example of 48754 is wrong. It is of no importance that IDTRANSACTIONS 12548 is repeated. :)
– Layla Comparin
Is this what you want? http://sqlfiddle.com/#! 9/cc7cef/21
– Sorack