MySQL Common query statement review

Source: Internet
Author: User

A note book that lets you review your sentences quickly.

CREATE TABLE Users (
Username varchar (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 rows all columns

SELECT * FROM Stu
--Some rows all columns
SELECT * from Stu where sid>3
--Some rows some columns
Select Sname from Stu where sid>=3
--All rows in a column
Select Sname from Stu

--mysql limiting 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

--Grouping
Select COUNT (*), age from the Users group by age
--After grouping the query using having
Select COUNT (*), age from the Users group by age has count (*) >=2

---null query
SELECT * from users where userpwd are NOT null

SELECT * from the users where age between and 30
SELECT * from users where username between ' a ' and ' l '

-In sub-query
SELECT * from Stu where SID in (1,2,3,4,7,6,8,9)

--Inner connection
SELECT * FROM Stu INNER join CJ as C on stu.sid=c. ' Sid '
where stu.sid=1

--Equivalent connection
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


---sub-query
SELECT * from Stu where age> (
Select age from Stu where sname= ' Lisi '
)

Reprinted from: http://blog.csdn.net/supera_li/article/details/9303709

MySQL Common query statement review

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.