Mysql 查询数据库最早一条记录和第一条数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Luomingkui1109/article/details/85051036

1.查询表中最早时间的一条记录

(1)错误的:select a.*,MIN(enter_time) from g2monitor_range_event a;

    解析:因为这样的话只是查询了数据库中的第一条记录,有查询了最早的时间,这是没有必然联系的。

(2)正确的:select * from g2monitor_range_event where enter_time in(select min(enter_time) from g2monitor_range_event);

2.查询数据库中第一条记录:

    select * from g2monitor_range_event limit 1;

猜你喜欢

转载自blog.csdn.net/Luomingkui1109/article/details/85051036