使用order by 字句进行排序
按照单个列排序
select studentid from tb_student order by studentid;
按照多个列排序
select studentid,studentage from tb_student order by studentagae,studentid;
排序按照order by 后面第一个列,如果第一个列相同,再按照第二个列。
指定排序方向
单个列排序
select * from tb_student order by studentid desc;
降序排列
多个列排序
select * from tb_student order by studentage desc,studentid;
desc 关键字运用于其前面的列名。
select * from tb_student order by studentage desc limit 1;
order by 和limit 结合,可以找到一个列中最低和最高的值。
select * from tb_student order by studentage asc limit 1;–asc是升序排列