For example: table name: players
sno | name | coach_id |
---|---|---|
1 | Sachin | 1 |
2 | Dravid | 5 |
3 | Kohli | 1 |
4 | Ganguly | 2 |
5 | Sehwag | 4 |
6 | Gambir | 3 |
Query:
SELECT one.sno, one.name FROM players AS one
WHERE ( SELECT COUNT(*) FROM players AS two WHERE two.sno <= one.sno ) <= 3
Output:
sno | name | coach_id |
---|---|---|
1 | Sachin | 1 |
2 | Dravid | 5 |
3 | Kohli | 1 |
No comments:
Post a Comment