Reputation: 13
I have a table with 2 columns in which one column is unique. I want to fetch records from table as below, I want to query from my sql developer to fetch records from the table where transaction id = 195865487, 201263012 and transaction sequence is 1,4,5,6,7 for 195865487 and 2,3,4,5,6,7 for 201263012 .
transaction id | transaction seq
----+-----------+-------------------
195865487 | 1
201263012 | 1
195865487 | 2
195865487 | 3
195865487 | 4
195865487 | 5
195865487 | 6
195865487 | 7
195865487 | 8
201263012 | 2
201263012 | 3
201263012 | 4
201263012 | 5
201263012 | 6
201263012 | 7
201263012 | 8
201263012 | 9
Upvotes: 0
Views: 1779
Reputation: 1
This will give you the required results
SELECT * FROM table
WHERE (transaction_id=195865487 AND transaction_seq IN (1,4,5,6,7))
OR (transaction_id=201263012 AND transaction_seq IN (2,3,4,5,6,7))
Upvotes: 0
Reputation: 14858
Construct where
condition like this:
select * from t
where (transaction_id = 195865487 and transaction_seq in (1,4,5,6,7))
or (transaction_id = 201263012 and transaction_seq in (2,3,4,5,6,7))
Upvotes: 1
Reputation: 379
Is this what you need?
SELECT * FROM some_table
WHERE transaction_id IN (195865487, 201263012)
AND (transaction_sequence IN (1,4,5,6,7)
OR transaction_sequence IN (2,3,4,5,6,7))
Upvotes: 0