Tengo las siguientes tablas:
users:
+----------------+-----------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-----------------+------+-----+-------------------+-----------------------------+
| id | int(6) unsigned | NO | PRI | NULL | auto_increment |
| firstname | varchar(30) | NO | | NULL | |
| lastname | varchar(30) | NO | | NULL | |
| birthday | datetime | NO | | NULL | |
| email | varchar(50) | NO | | NULL | |
| valid | tinyint(1) | NO | | 0 | |
| validationCode | varchar(255) | NO | | NULL | |
| password | varchar(255) | NO | | NULL | |
| reg_date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+----------------+-----------------+------+-----+-------------------+-----------------------------+
courses:
+-------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------+------+-----+---------+----------------+
| course_id | int(6) unsigned | NO | PRI | NULL | auto_increment |
| course_name | varchar(50) | NO | | NULL | |
| user_id | int(6) unsigned | NO | MUL | NULL | |
+-------------+-----------------+------+-----+---------+----------------+
subjects:
+---------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-----------------+------+-----+---------+----------------+
| subject_id | int(6) unsigned | NO | PRI | NULL | auto_increment |
| subject_name | varchar(255) | NO | | NULL | |
| teacher_name | varchar(255) | NO | | NULL | |
| subject_room | varchar(30) | NO | | NULL | |
| subject_color | varchar(50) | NO | | NULL | |
| course_id | int(6) unsigned | NO | MUL | NULL | |
+---------------+-----------------+------+-----+---------+----------------+
Lo que pretendo hacer es eliminar una asignatura de la tabla subjects
sabiendo la id del usuario y el nombre de la asignatura que se desea eliminar, lo que tengo hasta el momento es lo siguiente:
$drop = $conn->prepare("
DELETE subjects.*
FROM subjects users
INNER JOIN courses ON users.id = courses.user_id
INNER JOIN subjects ON courses.course_id = subjects.course_id
WHERE users.id = :userid AND subjects.subject_name = :subjectName
");
Haciendo esto, me devuelve el siguiente error:
Column not found: 1054 Unknown column 'users.id' in 'where clause''
Gracias de antemano por cualquier ayuda....