This article describes some common SQL statements in mysql, including instances with DISTINCTSELECTDELETETRUNCATEINSERTINTO.
This article describes some common SQL statements in mysql, including instances with DISTINCT SELECT DELETE TRUNCATE INSERT.
1. query the different parts of table A and table B.
Field not in (result set)
SELECT aurl FROM atab WHERE aurl not in (select distinct burl FROM btab)
Note: mysql supports subqueries from 5.0.
If you compare multiple fields, you can use concat to concatenate the fields into strings for comparison. For example:
SELECT aurl, aclass FROM atab where concat (aurl, aclass) not in (select distinct concat (burl, bclass) FROM btab)
2. Clear the content in table.
Delete from atab
Truncate table atab
To DELETE some 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 deleted records, while truncate table returns 0.
If an auto-increment field exists in a TABLE, after deleting all records using truncate table and DELETE without WHERE clause, the auto-increment field restores the starting value to 1. if you do not want to do this, you can add the permanent WHERE statement in the DELETE statement, such as WHERE 1 or WHERE true.
Delete from atabl WHERE 1
3. Add a specified column of a table to another table.
Insert into atab (aurl) SELECT burl FROM btab
Insert burl in the btab table to the aurl column in The atab table
Here we will introduce some basic-level statements. If you need them, refer to explain.