Home > Database > SQL > body text

What does 'select 1 from table' mean?

angryTom
Release: 2020-02-13 16:13:14
Original
20722 people have browsed it

What does 'select 1 from table' mean?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template