Home > OS >  In operator takes only one Id(if Id is repeating) from the list in sql server
In operator takes only one Id(if Id is repeating) from the list in sql server

Time:01-03

I have a query I am using IN operator and I want all the rows from in given list as shown in the picture that I want 3 rows for id 1 and one for id 2, but I only get one row for Id = 1 is there any other solution for this.

enter image description here

CodePudding user response:

IN can't do what you want. JOIN instead:

select * from logs
JOIN (values (1),(2),(1),(1)) x (id)
  ON logs.id = x.id
  • Related