Home > Database > Mysql Tutorial > body text

Detailed explanation about MySQL-retrieving data

jacklove
Release: 2018-06-14 16:17:53
Original
1695 people have browsed it

MySQL is not case-sensitive, but try to capitalize keywords and lowercase column sums to facilitate reading and debugging.

SQL statement, all spaces are ignored. The SQL statement can be given on one line or divided into many lines. Generally, is divided into multiple lines and written .

Auto-increment:

Some lists require unique values. MySQL can automatically assign an available number to each row without manually adding each row. Assign a unique value.

DESCRIBE = SHOW COLUMNS FROM

MySQL supports DESCRIBE as a shortcut for SHOW COLUMNS FROM. For example:

is equivalent to


Unsorted data:

If there is no explicit sorting in MySQL The structure of the query, the order of the returned data is meaningless. As long as the same number of rows are returned, it is normal.

When retrieving multiple columns, be sure to add both after the column name. You don’t need to add the last one.


Retrieve all columns:

give If the wildcard character * is specified, all columns will be returned.

Generally, wildcards are not used to retrieve all columns, but if the column name is not explicitly specified, it can be used to retrieve columns with unknown names.

SELECT returns all matching rows.


All the values ​​in a row (with duplicates) have been retrieved, so how to remove them? DISTINCT, only returns different values.


##LIMIT 5 means returning no more than 5 rows of SELECT;

LIMIT 5,5 means MySQL returns 5 rows starting from row 5; the first number is the starting position, and the second number is the number of rows to be retrieved.

Notes:

(1) Bring a The LIMIT value always starts from the first row, and the given number is the number of rows returned; with two values ​​LIMIT you can specify to start from the position where the row number is the first value.

(2) The first line retrieved is line 0 instead of line 1 (this is the same as the array); so LIMIT 1 retrieves the second line instead of line 1 One line.

(3) When there are not enough rows (for example, LIMIT 10,5 but there are only 13 rows in total), MySQL will return the most rows it can return.

In MySQL5 and above versions:

LIMIT 3,4 == LIMIT 4 OFFSET 3 # Take 4 lines starting from line 3

This article explains MySQL-retrieving data. For more related content, please pay attention to the php Chinese website.

Related recommendations:

sql Compare the time difference between two adjacent records

.net2.0 connection Mysql5 database configuration

##Detailed explanation of the difference between cookie and session


The above is the detailed content of Detailed explanation about MySQL-retrieving data. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!