sql select 1 code example

Example 1: select 1 from orders

select 1 from table will return the constant 1 for every row of the table. It's useful when you want to cheaply determine if record matches your where clause and/or join.

Example 2: SELECT 1 from table

select * from StudentTable;

-- output : 
+------+-------+
| id   | name  |
+------+-------+
|    1 | John  |
|    2 | Carol |
|    3 | Smith |
|    4 | Bob   |
+------+-------+
4 rows in set (0.00 sec)

-- EXAMPLE OF SELECT 1 
select 1 from StudentTable;

-- output :
+---+
| 1 |
+---+
| 1 |
| 1 |
| 1 |
| 1 |
+---+
4 rows in set (0.00 sec)

-- The above returns 1 four times for 4 records, 
-- and if we had 5 records then the above query 
-- would have returned 1 five times.

Tags:

Html Example