Home > Database > Mysql Tutorial > How to Generate a Number Sequence from 1 to 100 in SQL?

How to Generate a Number Sequence from 1 to 100 in SQL?

Linda Hamilton
Release: 2025-01-03 04:42:42
Original
675 people have browsed it

How to Generate a Number Sequence from 1 to 100 in SQL?

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
Copy after login

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template