Tuesday, March 27, 2012

Display limited records with out using LIMIT in MySQL

If you want to get display limited records with out using LIMIT option in MySQL.
For example: table name: players

snonamecoach_id
1Sachin1
2Dravid5
3Kohli1
4Ganguly2
5Sehwag4
6Gambir3

Query:
SELECT one.sno, one.name FROM players AS one
WHERE ( SELECT COUNT(*) FROM players AS two WHERE two.sno <= one.sno ) <= 3

Output:
snonamecoach_id
1Sachin1
2Dravid5
3Kohli1




No comments:

Post a Comment