tl:dr This command doesn't work :(
SELECT * FROM homework WHERE crn =138628 AND WHERE id NOT IN (SELECT id FROM studentHw WHERE codigoAlumno="214521671");
Sorry for spanish names
I want to compare two tables to find what id isn't in another table . I have two tables:
Homework Table: with a group code (crn) and an id(identify the homework)
+------------+------------+--------+-----+
| titulo | fecha | crn | id |
+------------+------------+--------+-----+
| Tarea 1 | 2018-03-14 | 138628 | 25 |
| Tarea 2 | 2018-03-14 | 138628 | 158 |
| Tarea 3 | 2018-03-14 | 138628 | 159 |
| Tarea 1 | 2018-03-15 | 125488 | 162 |
| Tarea 2 | 2018-03-15 | 125488 | 163 |
+------------+------------+--------+-----+
SELECT * FROM homework ;
I want to select only the elements with the crn equals to 138628 and after compare it with another table named studentHW (delivered homework):
studentHW
+-----+--------------+---------+--------+
| id | codigoAlumno | entrega | crn |
+-----+--------------+---------+--------+
| 25 | 214521671 | si | 138628 |
| 158 | 214521671 | si | 138628 |
| 159 | 214521671 | si | 138628 |
+-----+--------------+---------+--------+
SELECT * FROM studentHw;
I want to select all rows in Homework that are not in studentHomework
I check in stackoverflow for the answer I found this...
Mysql: Select rows from a table that are not in another
And I try with the following command but it doesn't work:
SELECT * FROM homework WHERE crn =138628 AND WHERE id NOT IN (SELECT id FROM studentHw WHERE codigoAlumno="214521671");
codigoalumno is a student id
I receive this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id NOT IN (SELECT id FROM studentHw)' at line 1