mysql - How to get all list of data from a table, where it does not appear on another? -


i have 5 tables per below. how possible me list of training companies not have training class data (which means no female or male students), within mysql query statement?

select training_companies.* training_companies left join training_centers on training_centers.training_company_id = training_companies.id left join training_center_programmes on training_centers.id = training_center_programmes.training_center_id left join training_class_data on training_class_data.training_center_programme_id = training_center_programmes.id training_companies.id null 

so far here, supposed wrong. kindly advise. thanks.

training_class_data id | student_category_id | training_centre_programme_id | female | male 1  | 1                   | 1                            | 10     | 10 2  | 1                   | 2                            | 10     | 10 3  | 2                   | 1                            | 10     | 10 4  | 3                   | 1                            | 10     | 10  training_programmes id | name 1  | yoga 2  | pilates  training_center_programmes id | training_center_id   | status | training_programme_id 1  | 1                    | 1      | 1 2  | 2                    | 1      | 1 3  | 3                    | 1      | 1 4  | 4                    | 1      | 2 5  | 5                    | 1      | 2  training_centers id | name          | address | postal code | training_company_id 1  | tf center 1   | abc     | 1234        | 1 2  | tf center 2   | abc     | 1234        | 1 3  | tf center 3   | abc     | 1234        | 1 4  | sft center 1  | xyz     | 2345        | 2 5  | sft center 2  | xyz     | 2345        | 2 6  | kft center 1  | cbd     | 4234        | 3  training_companies id | name              | address | postal code  1 | trim fitness      | abc     | 1234  2 | stay fit training | xyz     | 2345    3 | keep fit trainers | cbd     | 4234 

how possible me list of training companies not have training class data

you need use condition d.training_centre_programme_id null instead of training_companies.id null:

select distinct c.* training_companies              c left join training_centers           tc on tc.training_company_id         = c.id left join training_center_programmes p  on p.training_center_id           = tc.id left join training_class_data        d  on d.training_centre_programme_id = p.id d.training_centre_programme_id null; 

sql fiddle demo


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -