Reputation: 2860
My table is like:
now here I want to pass limit for particular voices_id.
I mean if I want just 3 records of particular voices_id then how to do so? (3 records for voices_id=153 & 154) where to pass limit ?
Upvotes: 2
Views: 202
Reputation: 44844
This is what you can do
select *
from table_name t1
where t1.voices_id in (153,154)
and
(
select count(*) from table_name t2
where t1.voices_id = t2.voices_id and t1.id <= t2.id
) <= 3
order by t1.voices_id
;
Here the condition t1.id <= t2.id
will give you last 3 entry per group, you can reverse it for first 3 entry.
Upvotes: 1
Reputation: 7343
It is as simple as this:
SELECT * FROM voices_talks WHERE voices_id=153 LIMIT 3
UNION ALL
SELECT * FROM voices_talks WHERE voices_id=154 LIMIT 3
Upvotes: 0