SQL writing specification and common SQL statements

Source: Internet
Author: User

Common Query Statements

SELECT *From table name "WHERE condition or GROUP by field name has" Order By field name sort by LIMIT initial value, quantity; SELECT Fname,id from TTT WHERE ID=1; SELECT fname,id from TTT WHERE fname='BBB'; SELECT fname,id from TTT WHERE fname='BBB'OR fname='AAA'; SELECT fname,id from TTT WHERE fname in ('BBB','AAA'); SELECT fname,id from TTT WHERE fname like'%b%'; SELECT fname,id from TTT WHERE fname like'%b'; SELECT fname,id from TTT WHERE fname like'%b_'; SELECT Fname fromRt2whereId>1; SELECT fname from TTT WHERE ID>1and id<3; = = SELECT fname from TTT WHERE id=2; SELECT* FROM TTT ORDER by ID ASC or DESC--sort function, ASC positive order, desc reverse Select* FROM TTT ORDER by RAND ()--Random Value Select* FROM TTT ORDER by RAND () LIMIT1; --random and display only one select at a time* FROM TTT LIMIT1; --Show only one select* FROM TTT ORDER by ID DESC LIMIT1; SELECT* FROM TTT LIMIT3,2; SELECT* FROM TTT ORDER by ID DESC LIMIT3,1; SELECT*From TTT ORDER by id desc,fnum ASC; SELECT*From test ORDER by CONVERT (Fname USING gb2312); Chinese sort Select*From TTT GROUP by Fnum; SELECT a.fid,b.fname,b.fsex from Product_category_test a,t2 B WHERE a.fid=b.fid: Function of PHP-like functions In_array () Select* FROM TTT WHERE find_in_set (1, Fcateids); SELECT COUNT (Fid) as totals from TTT; Name customization after as, alias Select* FROM Tb_school WHERE Fid in (SelectFid fromTb_users);

Add statement

Insert into TTT (fname,fnum) VALUES (' little cui ',1); insert into TTT (fname,fnum) VALUES (' Xiao Wang ',1); INSERT into TTT (fname,fnum) VALUES ('  Xiao Li ',1);

UPDATE statement

UPDATE ttt SET fname=' little cui '  WHERE condition; UPDATE TTT SET fname=' xiao Cui '; UPDATE TTT SET fname='cccc' WHERE id=4; -- non-existent data, table will not be made any changes to update TTT SET fnum=fnum+1 WHERE id=1;

Delete statement

Delete from table name where condition-----Delete table

Federated queries

 as  as 0 and T.subject <>") Order by T.tid DESC

SQL writing specification and common SQL statements

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.