Home > Database > Mysql Tutorial > MySQL simply implements the method of adding serial numbers to query results_MySQL

MySQL simply implements the method of adding serial numbers to query results_MySQL

WBOY
Release: 2016-07-06 13:32:47
Original
1288 people have browsed it

The example in this article describes the simple method of adding serial numbers to query results in MySQL. Share it with everyone for your reference, the details are as follows:

First method:

The code is as follows:

select (@i:=@i 1) as i,table_name.* from table_name,(select @i:=0) as it


Second method:

set @rownum=0;
select @rownum:=@rownum+1 as rownum, t.username from auth_user t limit 1,5;

Copy after login

Readers who are interested in more MySQL-related content can check out the special topics on this site: "A Complete Collection of MySQL Log Operation Skills", "A Summary of MySQL Transaction Operation Skills", "A Complete Collection of MySQL Stored Procedure Skills", and "A Summary of MySQL Database Lock Related Skills" 》and《Summary of commonly used functions in MySQL》

I hope this article will be helpful to everyone in MySQL database planning.

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template