MySQL common SQL statements

Source: Internet
Author: User
Select * From table1select * From Table1 where ID> = 1 and ID <= 20 and ID in (1, 2, 4, 5, 6, 7, 8, 9) or (ID between 1 and 10) select * From table3 where t3date> = '2014-08-10 'select * From Table1 where ID is not null group by ID, t1name order by ID, t1nameselect sum (ID) from table1select count (*) from table1select * from (select. *, B. t2value from Table1 a left join Table2 B on. id = B. t2table1id) aselect. *, B. * From Table1 a left join Table2 B on. id = B. t2table1id/* shows all data in Table A and all data in Table B that meet the association conditions. If table B contains multiple rows that meet the conditions in Table A, all the rows in Table B are displayed, the displayed content of table A is the same. If a data entry in Table A is not associated with data in Table B, the column B corresponding to the record in the query result is null and empty */select. *, B. * From Table1 a right join Table2 B on. id = B. t2table1id/* displays all data in Table B and all data that meet the association conditions in table. If a piece of data in Table B is not associated with data in Table A, the query result shows that the column corresponding to Table A is null and empty */select. *, B. * From Table1 a inner join Table2 B on. id = B. t2table1id/* only display all data in table B of Table A corresponding to the other party */-- return the id value of the last inserted database select @ identity as ID; select last_insert_id () as ID; update table4 a left join table5 B on. table5_id = B. id set. name = Concat (. name, '.html ') Where B. id = 1; -- Concat (. name, '.html ') Concat () returns after two strings are connected -- batch insert into Table1 (ID, t1name) values (1, 'name1'), (2, 'name2'), (3, 'name3'); Create Table table6 as select. ID, B. name from table4 a left join table5 B on. table5_id = B. ID where B. id = 1; -- create a new table using the query results.

 

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.