How to show a list of items NOT IN a certain MySQL table? This query isn't working -


i have list of courses (that can open or closed) , list of users (that can enrolled 1 or more courses).

i have 3 tables: usuarios (for users), cursos(for courses) , cursosusuarios (that links 2 know who's enrolled where).

i want show list of available courses specific user (ie. uid 18) not enrolled.

i'm trying query, that's not working:

select cursos.cursoid, cursos.nombrecurso, cursos.cursofechainicio,         cursos.modalidadcurso, cursos.estadocurso,        cursosusuarios.userid, cursosusuarios.cursoid cursos      left join cursosusuarios on cursos.cursoid = cursosusuarios.cursoid cursosusuarios.userid not in (                                     select cursosusuarios.userid                                      cursosusuarios                                    ) , estadocurso='abierto' , cursosusuarios.userid = 18 

these tables:

create table cursos (     cursoid int unsigned not null auto_increment primary key,     nombrecurso char(100) not null,     cursofechainicio char(10) null,     modalidadcurso char(50) not null,     estadocurso char(50) not null, )  create table usuarios(     userid int unsigned not null auto_increment primary key, )  create table cursosusuarios (     cursosusuariosid int unsigned not null auto_increment primary key,     userid int not null,     cursoid int not null ) 

move condition where join on clause like

from cursos left join cursosusuarios on cursos.cursoid = cursosusuarios.cursoid , cursosusuarios.userid <> 18 estadocurso='abierto' 

Comments