SQL statement Two

Source: Internet
Author: User

Select single column data
Select name from Totoro;
Select two columns of data
Select Id,name from Totoro;
Select data that is not duplicated in a single column
Select distinct name from Totoro;
Select the name in the Name column as the pangpang3 data
SELECT * from Totoro where name= ' pangpang3 ';
Select the age>3 data
SELECT * FROM Totoro where age>3;
and
SELECT * from Totoro where id=1 and age=1;
or
SELECT * from Totoro where id=1 or age=3;
ORDER by sort
Select age from Totoro order by age;
Select two columns, sort by age
Select Id,age from Totoro order by age;
DESC, descending
Select Age,name from Totoro order by name DESC;
ASC, ascending
Select Name,id from Totoro order by name ASC;
Partial Insertion
Insert into Totoro (id,name) VALUES (, ' Feifei ');
Partial Update
Update Totoro set id=13,name= ' Mark ' where age=9;
Delete
Delete from Totoro where id=1;
Select the first 3 lines limit
SELECT * from Totoro limit 3;
the name ending with I
SELECT * from Totoro where name is like '%i ';
name with Om
SELECT * from Totoro where name is like '%om% ';
name the first word specifier is Hu's
SELECT * from Totoro where name is like ' _hu ';
name 2nd is a, and the 4th is K.
SELECT * from Totoro where name is like ' _a_k ';
name is tom,ii
SELECT * from Totoro where name in (' Tom ', ' II ');
take the name between Anan and Mary
SELECT * from Totoro where name between ' Anan ' and ' Mary ';
As specifies an alias
Select Name as n from Totoro;
table name Totoro as T
Select T.id from Totoro as T;
two name in table with ID equal
Select Totoro.id,totoro.name,user.name from Totoro,user where totoro.id=user.id;
join on
Select Totoro.id,totoro.name,user.name from Totoro join user on Totoro.id=user.id order by Totoro.id;
Take two data with the same ID in the table
Select Totoro.id,totoro.name,user.name from Totoro,user where totoro.id=user.id;
INNER JOIN
Select Totoro.id,totoro.name,user.id from Totoro inner JOIN user on Totoro.id=user.id order by Totoro.id;

SQL statement Two

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.