sql >> Base de Datos >  >> RDS >> Mysql

Error al usar excepto en una consulta

No creo que MySQL admita la sintaxis EXCEPTO. Intenta usar NOT IN o un LEFT JOIN :

SELECT s.sno 
FROM students s    
WHERE s.sno NOT IN 
(
    SELECT t.sno 
    FROM take t 
    WHERE t.cno = 'CS112'
);

O

SELECT s.sno 
FROM students s    
    LEFT JOIN take t ON s.sno = t.sno
WHERE IFNULL(t.cno, '') != 'CS112'

ACTUALIZAR

Me burlé de sus datos como tales y devuelve correctamente del 5 al 10:

create temporary table temp_students (sno int)

insert into temp_students values (1)
insert into temp_students values (2)
insert into temp_students values (3)
insert into temp_students values (4)
insert into temp_students values (5)
insert into temp_students values (6)
insert into temp_students values (7)
insert into temp_students values (8)
insert into temp_students values (9)
insert into temp_students values (10)

create temporary table temp_take (sno int, cno varchar(50))

insert into temp_take values (1, 'CS112')
insert into temp_take values (2, 'CS112')
insert into temp_take values (3, 'CS112')
insert into temp_take values (4, 'CS112')

SELECT s.sno 
FROM temp_students s    
        LEFT JOIN temp_take t ON s.sno = t.sno
WHERE IFNULL(t.cno, '') != 'CS112'