MySQL Learning summary----Single-table data query

Source: Internet
Author: User

MySQL Learning summary----Single-table data query

=================================================================================

First, the basic data record query

=================================================================================

1. Simple data query

    • Select id,name,sex,class,address from qiuuuu; query all information in the table qiuuuu;

    • Select Id,name,sex from Qiuuuu; The fields in the query table qiuuuu id,name,sex All information for three properties;

    • Select * from qiuuuu; query all information for all fields in table qiuuuu;

2. Avoid duplicate data query distinct

    • Select DISTINCT class from qiuuuu; query table qiuuuu all records about attribute class, no duplicates;

3, arithmetic character query

+ Addition
- Subtraction
* Multiplication
/ Division
% Seeking redundancy
    • Select id*2 from qiuuuu

4. Display Format data query

mysql> Select concat (name, '------test: ', id) hello from qiuuuu;

Concat the connection string, enclosing the property name and string in parentheses, followed by the printed table name.

+-------------------+

| Hello |

+-------------------+

| James------Test:1 |

| Allen------Test:2 |

| Zhang------Test:3 |

| XI------Test:3 |

| XI------Test:3 |

| Li------Test:3 |

| Wang------Test:3 |

+-------------------+

7 Rows in Set (0.00 sec)

=================================================================================

Second, the condition data record query

=================================================================================

In the MySQL database, the query is implemented through the SQL statement Select, while filtering the queried data records through the keyword where syntax is as follows:

Select Property Name 1, property name 2, property name 3,....., property name n from Qiuuuu where ...

You can answer the keyword in the following field:

    • Between and

    • Is null

    • Inch

    • Like

Comparison operators are:

> Greater than
< Less than
= Equals
! = or <> Not equal to
>= Greater than or equal
<= Less than or equal

The logical operators are:

And OR && And
OR OR | | Logical OR
Xor XOR or
Not OR! Non -


=================================================================================

Third, sort data record query

=================================================================================

Select Property Name 1, property name 2, property name 2,......, property name n from table name

where CONDITION order by property name M [Asc|desc] [, property name I [Asc|desc],]

1. Sort by single field

    • Select ID from qiuuuu where class= ' 3 ' ORDER by id desc; Descending

    • Select ID from qiuuuu where class= ' 3 ' ORDER by ID ASC; Ascending (the default ascending order)

2. Sort by multiple fields

SELECT * from qiuuuu where class= ' 3 ' ORDER by ID desc,address ASC;


=================================================================================

Iv. limit the number of data record queries

=================================================================================




================================================================================

V. Statistical functions and packet data record queries

=================================================================================






















This article from "Doublelinux" blog, declined reprint!

MySQL Learning summary----Single-table data query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.