简体   繁体   English

从一个表中获取第一行和最后一行

[英]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 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从表中获取小时内的第一行和最后一行 - How to get first and last row in hour from table PHP:从一个 mysql 表中获取最后一行的 id 号,并使用它来更新另一个表的第一行中的字段 - PHP: Taking the last row's id number from one mysql table and using it to update a field in the first row of another table 连接 - 从一个表中获取行然后获取另一个表中匹配的所有行? 但不应重复第一个表匹配行 - Joins - get row from one table then get all rows that match in another table? but first table matching row should not be repeated 获取 MySQL 表中一组行中最后一个不同行的第一次出现 - get first occurrence of last different row in a group of rows in MySQL table 读取一个表并从另一个表中获取与第一个表行相关的行 - Read one table and get rows from another table relevant to first tables row 如何从具有相同日期的表(查询)中获取最后的第一和最后一个? - How to get last first and last from table with same date (query)? 如何遍历表格从最后一行到第一行? - How to iterate through a table from last row to first? 如何从一个表中选择最后一行,然后更新另一个表的最后一行? - How to select the last row from one table then update the last row of another one? 如何从分组行中的第一行/最后一行获取价值? - How to get value from the first/last row in grouped rows? 在MySQL中联接三个表,并获得每个ID一行(第一个表中的每个实体一行) - Join three table in MySQL and get one row per id (one row per each entity in first table)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM