0

I have a SELECT * FROM blabla WHERE id IN (1,2,3,4,5).. How can I get LIMIT of 1 for EACH value inside IN?

If I do: SELECT * FROM blabla WHERE id IN (1,2,3,4,5) LIMIT 1 i only get 1 result, what I want is 1 from 1, 1 from 2, 1 from 3, etc..

user3314517
  • 147
  • 1
  • 2

2 Answers2

0

You could group by the IDs.

SELECT * 
FROM blabla 
WHERE id IN (1,2,3,4,5) 
GROUP BY id

This should return one row per id.

You may reconsider your tablestructure, if there are multiple rows with the same id, the reason for the use of IDs may be obsolete...

32bitfloat
  • 751
  • 2
  • 8
  • 21
0

simple group by will do the trick

select *
from blabla bl
WHERE id IN (1,2,3,4,5)
group by id
Tzook Bar Noy
  • 11,337
  • 14
  • 51
  • 82