bano590
bano590

Reputation: 39

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?

Upvotes: 1

Views: 470

Answers (2)

AhDev
AhDev

Reputation: 486

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?

Upvotes: 2

Hugo Dias
Hugo Dias

Reputation: 169

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)"

Upvotes: 0

Related Questions