What does "select 1 from table" mean?
select 1 from table and Select * from table are similar in usage. For detailed analysis, see Below:
1. There is no difference in function between select 1 from mytable; and select anycol (any row in the destination table collection) from mytable; and select * from mytable. They both check whether there is a record. Generally used for conditional purposes.
The 1 in select 1 from is a constant, and the value of all the rows found is it, but in terms of efficiency, 1>anycol>*, because there is no need to look up the dictionary table.
2. To view the number of records, you can use select sum(1) from mytable; which is equivalent to select sum(*) from mytable;
Recommended related articles and tutorials: mysql tutorial
The above is the detailed content of What does 'select 1 from table' mean?. For more information, please follow other related articles on the PHP Chinese website!