How to get first and last record from a table? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to get first and last record from a table?

1st Sep 2016, 4:39 AM
Kirtiranjan Sahoo
Kirtiranjan Sahoo - avatar
3 Answers
+ 2
you can to try this: SELECT columns FROM table ORDER BY id DESC LIMIT 1 UNION ALL SELECT columns FROM table ORDER BY id ASC LIMIT 1
1st Sep 2016, 12:41 PM
Andrei Berval
Andrei Berval - avatar
+ 1
Select * from (select * from table_name order by rownum desc) where rownum=1 Union Select * from(select * from table_name order by rownum) where rownum =1; I found this solution
2nd Sep 2016, 3:31 AM
Kirtiranjan Sahoo
Kirtiranjan Sahoo - avatar
- 1
select columnname from tablename where firstname ='' and lastname ='';
1st Sep 2016, 6:09 AM
jambulingam R