What does it mean by select 1 from table?

前端 未结 15 1839
南方客
南方客 2020-12-07 07:32

I have seen many queries with something as follows.

Select 1  
From table

What does this 1 mean, how will it be executed and,

15条回答
  •  温柔的废话
    2020-12-07 08:05

    If you don't know there exist any data in your table or not, you can use following query:

    SELECT cons_value FROM table_name;
    

    For an Example:

    SELECT 1 FROM employee;
    
    1. It will return a column which contains the total number of rows & all rows have the same constant value 1 (for this time it returns 1 for all rows);
    2. If there is no row in your table it will return nothing.

    So, we use this SQL query to know if there is any data in the table & the number of rows indicates how many rows exist in this table.

提交回复
热议问题