I have the following tables:
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 | |
+-------------+-----------------+------+-----+---------+----------------+
subject :
+---------------+-----------------+------+-----+---------+----------------+
| 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 | |
+---------------+-----------------+------+-----+---------+----------------+
What I intend to do is delete a subject from the table subjects
knowing the user id and the name of the subject to be deleted, what I have so far is the following:
$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
");
Doing this gives me the following error:
Column not found: 1054 Unknown column 'users.id' in 'where clause''
Thanks in advance for any assistance....
The sentence would be the following:
I hope my answer helps you, greetings.