0

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
6
  • Please show the example results you want, at present I can't figure out what you're trying to describe. Also, why did you put 201263012,1 in second row of your example data, rather than just before 201263012,2? Is that significant in some way? (Is there another column, such as a timestamp, that determines that position?) You then mention transaction sequence is 1,4,5,6,7, but your sample data has no such sequence? Commented Mar 28, 2019 at 13:22
  • Please re-read you question and consider if you would understand it without prior knowledge. Commented Mar 28, 2019 at 13:24
  • results I'm excepting are transaction id | transaction seq ----+-----------+------------------- 195865487 | 1 195865487 | 4 195865487 | 5 195865487 | 6 195865487 | 7 201263012 | 2 201263012 | 4 201263012 | 5 201263012 | 6 201263012 | 7 Commented Mar 28, 2019 at 13:31
  • transaction sequence? In any order? Or does your table have a timestamp column as well? Commented Mar 28, 2019 at 13:36
  • transaction sequence in any order. I do not have a timestamp in the table. Commented Mar 28, 2019 at 13:43

3 Answers 3

1

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))

demo

Sign up to request clarification or add additional context in comments.

Comments

0

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))

Comments

0

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.