How to Retrieve an Ordered List of Numbers from 1 to 100 Using SQL
To generate a list of consecutive numbers from 1 to 100 using SQL, the DUAL table can be leveraged effectively. The DUAL table is a special table in SQL that contains a single row and a single column with the value 'X'. By leveraging this table in conjunction with rownum and the CONNECT BY syntax, it is possible to create a sequence of numbers.
To accomplish this, the following SQL statement can be employed:
Select Rownum r From dual Connect By Rownum <= 100
This query selects the rownum (row number) as 'r'. The DUAL table provides a single row, and the CONNECT BY syntax generates additional rows by recursively adding 1 to the rownum value. The condition Rownum <= 100 limits the number of rows generated to 100, resulting in a list of numbers from 1 to 100.
The above is the detailed content of How to Generate a Number Sequence from 1 to 100 in SQL?. For more information, please follow other related articles on the PHP Chinese website!