table表是一个数据表,假设表的行数为10行。
1:select 1 from table 增加临时列,每行的列值是写在select后的数,这条sql语句中是1
2:select count(1) from table 不管count(a)的a值如何变化,得出的值总是table表的行数
3:select sum(1) from table 计算临时列的和
select 1 from table 与Select * from table在用法上大同小异,具体不同分析见下文:
1、select 1 from mytable;与select anycol(目的表集合中的任意一行) from mytable;与select * from mytable 作用上来说是没有差别的,都是查看是否有记录,一般是作条件用的。select 1 from 中的1是一常量,查到的所有行的值都是它,但从效率上来说,1>anycol>,因为不用查字典表。
2、查看记录条数可以用select sum(1) from mytable;等价于select sum() from mytable;