Summary of statements commonly used by MySQL in projects

Source: Internet
Author: User

Let you quickly review the notes of the statement.

Create Table users (
Username varchar (20) primary key,
Userpwd varchar (20)
)

Alter table users add age int

Insert into Stu (sname) values ('sdfdsfdsfeeeeee ')
Update CJ set Cj = 60 Where sid = 1

Delete from CJ where Sid = 2

-- All columns in all rows

Select * from Stu
-- All columns of some rows
Select * from Stu where Sid> 3
-- Some rows and columns
Select sname from Stu where Sid> = 3
-- All rows in a column
Select sname from Stu

-- MySQL limits M Stu limit 3

Select * from Stu limit 3, 2

-- Sort
Select * from Stu order by SID ASC

-- Fuzzy search
Select * from Stu where sname like '% Aa %'

-- Aggregate function usage
Select sum (C. CJ) from CJ as C

Select count (*) from Stu

Select count (userpwd) from users

-- Group
Select count (*), age from Users Group by age
-- Use having for grouping queries
Select count (*), age from Users Group by age having count (*)> = 2

--- Null Query
Select * from users where userpwd is not null

Select * from users where age between 20 and 30
Select * from users where username between 'a 'and 'l'

-- In subquery
Select * from Stu where Sid in (1, 2, 3, 4, 7, 6, 8, 9)

-- Internal Connection
Select * from Stu inner join CJ as C on Stu. Sid = C. 'sid'
Where Stu. Sid = 1

-- Equijoin
Select * from Stu, CJ as C where Stu. Sid = C. 'sid'

-- External Connection
Select * from CJ as C right join Stu on Stu. Sid = C. Sid

--- Subquery
Select * from Stu where age> (
Select age from Stu where sname = 'lisi'
)

Select * from Stu
Select * from CJ

Select * from Stu where sid not in (
Select Sid from CJ
)

Select * from Stu inner join CJ as C on Stu. Sid = C. Sid

Select * from Stu left join CJ as C on Stu. Sid = C. Sid
Where C. 'sid 'is null

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.