简体   繁体   中英

MySQL: Deleting table rows from different tables

I want to delete a row from a table of MySQL database

SQL Query:

DELETE FROM students WHERE tutor_availability = student_availability;

tutor_availabilty is contained within another table called tutors . Possibly worth noting that I am using xampp. Wondering if anyone could help me with this?

Depending on what it is you are actually trying to delete and how your records are related you may want to use and IN instead of a JOIN. This may also be a little easier to visualize.

For example:

DELETE FROM students where student_availability 
IN (Select tutor_availability FROM tutors)

Here is a good explanation of JOIN vs IN:

SQL JOIN vs IN performance?

Didn't get the full picture here, but after reading like 10 times i think you have the following structure

  • Table - Stutends (id, student_avaliability, tutor_id...)
  • Tutors (id, tutor_avaliability, ... )

So, you may want to try this:

"DELETE FROM students WHERE students.student_availability = tutors.tutor_availability INNER JOIN tutors ON (students.tutor_id = tutors.id)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM