MySQL multiple table Delete instance

Source: Internet
Author: User

MySQL multiple table Delete


Delete A student's basic information while deleting all of the student's achievements

mysql> select * from stu_inf;+----+----------+--------+-------+-------+--------+|  Id | stu_xh   | stu_xm | xb_id | xy_id | stu_bj  |+----+----------+--------+-------+-------+--------+|  1 | 07150101 |  Xiao Ming    |     1 |     1 | 1504    | |   2 | 07150240 |  Shei  |     1 |      2 | 1502   | |   3 | 12341231 |  Monkey    |     1 |      2 | 1515   | |   4 | 01591261 |  Big    |     1 |      3 | 1515   | |   5 | 07160202 |  Little Red    |     2 |     4 |  1602   | |   6 | 07150225 |  Huanghe    |     1 |      3 | 1315   | |   7 | 01050001 |  Huarong    |     1 |      7 | 1612   | |   8 | 02050002 |  huangyueying  |     2 |      8 | 1608   | |   9 | 01510003 |  Huan Huan    |     2 |      9 | 1601   | |  10 | 05261005 |  Tai Kang    |     1 |     10 | 1304   | |  13 |&Nbsp;0001     | xxx    |     1  |     2 | 1555   |+----+----------+--------+-------+-- -----+--------+11 rows in set  (0.02 sec) mysql> select * from  cj_inf;+-------+----------+---------+----------+| cj_id | cj_stuid | cj_kmid |  cj_score |+-------+----------+---------+----------+|     1 |         3 |       1 | 87        | |      2 |        1 |        2 | 65       | |      3 |        4 |        1 | 77       | |      5 |        3 |        9 | 76       | |      7 |        1 |        1 | 90       | |     15 |       13 |        9 | 90       | |     16 |       13 |        8 | 67       | |     13 |       13 |        1 | 88        |+-------+----------+---------+----------+8 rows in set  ( 0.02 SEC)


Delete statement:

Mysql> DELETE Stu_inf,cj_inf from Stu_inf left joins Cj_inf on Stu_inf.id=cj_inf.cj_stuid WHERE stu_inf.id=13; Query OK, 4 rows Affected (0.00 sec)


After executing the statement:

mysql> select * from stu_inf;+----+----------+--------+-------+-------+--------+|  Id | stu_xh   | stu_xm | xb_id | xy_id | stu_bj  |+----+----------+--------+-------+-------+--------+|  1 | 07150101 |  Xiao Ming    |     1 |     1 | 1504    | |   2 | 07150240 |  Shei  |     1 |      2 | 1502   | |   3 | 12341231 |  Monkey    |     1 |      2 | 1515   | |   4 | 01591261 |  Big    |     1 |      3 | 1515   | |   5 | 07160202 |  Little Red    |     2 |     4 |  1602   | |   6 | 07150225 |  Huanghe    |     1 |      3 | 1315   | |   7 | 01050001 |  Huarong    |     1 |      7 | 1612   | |   8 | 02050002 |  huangyueying  |     2 |      8 | 1608   | |   9 | 01510003 |  Huan Huan    |     2 |      9 | 1601   | |  10 | 05261005 |  Tai Kang    |     1 |     10 | 1304   |+----+----------+--------+-------+-------+--------+10 rows in set  (0.00 sec) mysql> select  * from cj_inf;+-------+----------+---------+----------+| cj_id | cj_stuid  | cj_kmid | cj_score |+-------+----------+---------+----------+|      1 |        3 |        1 | 87       | |      2 |        1 |        2 | 65       | |      3 |        4 |        1 | 77       | |      5 |        3 |        9 | 76       | |      7 |        1 |        1 | 90       |+-------+----------+ + --------+----------+5 rows in set  (0.02 sec)


This article is from the "Kurol.blog" blog, make sure to keep this source http://kurol.blog.51cto.com/11433546/1923998

MySQL multiple table Delete instance

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.