Some common SQL statements in MySQL

Source: Internet
Author: User
Tags one table


1. Query a table in the different parts of table B
Field not in (result set)

Select Aurl from Atab WHERE aurl isn't in (select DISTINCT burl from Btab)
Note: MySQL supports subqueries starting at 5.0.

If you compare multiple fields, you can use Concat to connect the fields to string comparisons. Such as:

Select Aurl,aclass from Atab WHERE CONCAT (Aurl,aclass) isn't in (select DISTINCT CONCAT (burl,bclass) from btab)

2. Clear the contents of table A
DELETE from Atab

TRUNCATE TABLE Atab


If you want to delete some of the records in a table, you can only use the DELETE statement.

DELETE from Atab WHERE aid>1

If Delete does not add a WHERE clause, it is the same as the TRUNCATE table, but they are a little different, delete can return the number of records deleted, and TRUNCATE TABLE returns 0.

If you have a self added field in a table, and you delete all records using the TRUNCATE table and delete without the WHERE clause, the field returns the starting value to 1. If you don't want to do this, you can add a forever where in the DELETE statement, such as where 1 or where true.

DELETE from Atabl WHERE 1

3. Add the specified column of one table to another table
INSERT into Atab (aurl) SELECT Burl from Btab

Insert the Burl in the Btab table into the Aurl column in the Atab table

Here are some of the MySQL tutorials are introductory level statements, the need for friends can refer to the next.

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.