How to query and delete a MySQL join table

Source: Internet
Author: User

MySQL join Table query and join table deletion are all frequently used operations. The following sections describe MySQL join Table query and table deletion in detail and hope to help you.

MySQL join Table query:

Reference mysql manul:
3.2.7. SELECT syntax 13.2.7.1. JOIN syntax
13.2.7.2. UNION syntax
Eg1: · mysql> SELECT t1.name, t2.salary FROM employee AS t1, info AS t2 ·-> WHERE t1.name = t2.name; eg2: · mysql> SELECT table1. * FROM table1 ·-> left join table2 ON table1.id = table2.id ·-> WHERE table2.id is null;

Join table deletion:

1. Delete all matching records with id values in Table T2.

DELETE t1 FROM t1, t2 WHERE t1.id = t2.id or delete from t1 USING t1, t2 WHERE t1.id = t2.id

2. Find and delete no matching records in data table T2.

DELETE t1 FROM t1 left join T2 ON t1.id = t2.id WHERE t2.id is null or

Delete from t1, USING t1 left join T2 ON t1.id = t2.id WHERE t2.id IS NULL

3. Find the data with the same record from the two tables and delete the data from both tables.

DELETE t1, t2 from t1 left join t2 ON t1.id = t2.id WHERE t1.id = 25

Note that delete t1, t1 in t2 from, and t2 cannot be aliases.

For example, delete t1, t2 from table_name as t1 left join table2_name as t2 on t1.id = t2.id where table_name.id = 25 execution in data is incorrect MYSQL version not less than 5.0 is acceptable in 5.0)

The preceding statement is rewritten

Delete table_name, table2_name from table_name as t1 left join table2_name as t2 on t1.id = t2.id where table_name.id = 25 execution in the data is incorrect. MYSQL versions earlier than 5.0 are acceptable in MYSQL 5.0)

Introduction to MySQL CONVERT Functions

How to modify MySQL character set in Liunx

Take you to understand mysql Variables

Provides you with an in-depth understanding of MySQL user permissions.

MySQL user permission setting method

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.