查找最晚入职员工的所有信息,为了减轻入门难度,目前所有的数据里员工入职的日期都不是同一天(sqlite里面的注释为--,mysql为comment) CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, -- '员工编号' `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`));
select * from employees order by hire_date desc limit 1; /* 使用limit 与 offset关键字 */ select * from employees order by hire_date desc limit 1 offset 0; /* 使用limit关键字 从第0条记录 向后读取一个,也就是第一条记录 */ select * from employees order by hire_date desc limit 0,1; /* 使用子查询,最后一天的时间有多个员工信息 */ select * from employees where hire_date = (select max(hire_date) from employees);