MySQL Common query operations

Source: Internet
Author: User

Here is a summary of common MySQL database queries:


Displays all data for a data table.

Mysql> SELECT * FROM [table name];


Returns the column information for the specified data table.

Mysql> Show columns from [table name];


Use the value "blog" Filter to display selected rows.

Mysql> select * FROM [table name] WHERE user = "blog";


Displays all records that contain the name "Bob" and the phone number "5889".

Mysql> SELECT * FROM [table name] WHERE name = "Bob" and Phone_number = ' 5889 ';


Displays all records that do not contain the name "Bob" and the phone number is "5889" and is sorted in the Phone_number field.

Mysql> select * FROM [table name] WHERE name! = "Bob" and Phone_number = ' 5889 ' ORDER by Phone_number;


Displays all records with the name beginning with the letter "Bob" and the phone number "5889".

Mysql> select * FROM [table name] WHERE name is like "bob%" and Phone_number = ' 5889 ';


Displays the 1th to 5th Records whose name begins with the letter "Bob" and the phone number is "5889".

Mysql> select * FROM [table name] WHERE name is like "bob%" and Phone_number = ' 5889 ' limit 1, 5;


Use regular expressions to find records. Use regular expression binary to enforce case sensitivity. This command finds any records that begin with a.

Mysql> select * FROM [table name] WHERE rec rlike "^a";


Returns the only distinct record.

mysql> SELECT DISTINCT [column name] from [table name];


Displays the selected record in ascending or descending order.

Mysql> SELECT [col1],[col2] from [table name] ORDER by [col2] DESC;


Returns the number of rows.

Mysql> SELECT COUNT (*) from [table name];


Counts the sum of the specified column values.

Mysql> SELECT SUM (*) from [table name];


junction table.

Mysql> Select Lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid= Person.personid=statement to join birthday in person table with primary illustration ID;



Create the data table Example 1.

mysql> CREATE TABLE [table name] (firstname varchar), MiddleInitial varchar (3), LastName varchar, suffix varchar (3), OfficeId varchar (+), UserID varchar (username), varchar (8), email varchar (+), phone varchar (+), groups varchar ( ), Datestamp Date,timestamp time,pgpemail VARCHAR (255));


Create the data table Example 2.

mysql> CREATE TABLE [table name] (PersonID int () NOT NULL auto_increment primary key,firstname varchar), MiddleName varchar (+), Lastnamevarchar (() Default ' Bato ');




This article is from the "Bill of Operations Notes" blog, please be sure to keep this source http://chenshoubiao.blog.51cto.com/6159058/1842664

MySQL Common query operations

Related Article

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.