简体   繁体   中英

Get the first and the last row from one table

I want to get the first and the last row from a table. Once i get that, i want to get another first and last row from another table.

Is some strange i think, but this is it.

please, maybe somebody can give me an advice for what i want.

This is where i'm stuck :

http://s14.postimage.org/sj9xgeofz/print.png

Try using this:-

SELECT column name
 FROM table1
 WHERE <conditions>
 ORDER BY date DESC
 LIMIT 1
 UNION
 SELECT column name
 FROM table1
 WHERE <conditions>
 ORDER BY date ASC
 LIMIT 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM