Home >Database >Mysql Tutorial >How to Create a Sequential Number List in SQL?
How to Generate a Sequential Number List in SQL
Generating a list of numbers in a sequence, such as from 1 to 100, is a common task in many SQL applications. Using the DUAL table, you can achieve this with the following query:
Select Rownum r From dual Connect By Rownum <= 100
The DUAL table is a single-row table that serves as a placeholder in SQL. When used in the CONNECT BY clause, it creates a hierarchical structure where each row is connected to the next row. The Rownum column represents the position of each row in the hierarchy, providing the sequential numbers in this case.
The Connect By clause specifies the condition under which the hierarchy is built. In this case, the condition is "Rownum <= 100", which ensures that the hierarchy terminates after row 100 and produces a list of numbers from 1 to 100.
The above is the detailed content of How to Create a Sequential Number List in SQL?. For more information, please follow other related articles on the PHP Chinese website!