php - SQL joining other table with condition -


i have query:

select *  `classes`  join `classes_students`  on `classes`.`id` = `classes_students`.`class` 

and need add condition selecting classes, in not logged student (user id not in classes_students connected class id) , count how many students in class.

table structure: classes: id, name, etc classes_students: class_id, user_id, etc

table data:

classes:  1 | test  2 | test2 3 | test3  classes_students: 1 | 1 1 | 2 2 | 3 3 | 4 3 | 5 

expected output if im user id 1: classes names (with number of students in):

2 (1 student) 3 (2 students) 

all in 1 query. possible? if yes, how?

select classid, count(*) class   left join student on student.classid = class.classid group classid 

glad you


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -