Friday, January 7, 2011

Selecting First and last record of a table in mysql


We can do this  by using  UNION as follows:
Table Student is As follows:

id
Name
1
Shyam
2
Manu
3
Murari
4
Ranu
5
Pankaj

Select A.id,A.name from (select id,name from  student  order by id asc limit 1) A UNION select B.id,B.name  from (select id,name  from student  order by id desc limit 1)B

After Execution of this Query we will get
Id
name
1
Shyam
5
Pankaj

No comments:

Post a Comment

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...