SQL Query is only selecting 2 out of 4 records - MySQL Workbench -
trying select 4 fund names , relating contacts. however, 2 being selected. want able select 4 funds regardless if have associated contact names.
below sql:
select mutual_fund_name, concat(contact_first_name,' ',contact_last_name) mutual_fund mf, contact c, mutual_fund_has_contact mfhc, institution i, institution_has_mutual_fund ihmf mf.mutual_fund_id = mfhc.mutual_fund_id , c.contact_id = mfhc.contact_id , ihmf.mutual_fund_id = mf.mutual_fund_id , i.institution_id = ihmf.institution_id , mf.mutual_fund_name in ('vanguard balanced index fund', 'vanguard consumer discretionary index fund', 'vanguard extended market index fund', 'vanguard growth index fund') order mutual_fund_name;
how funds contacts (regardless if fund has any) return in sql statement?
i'm not sure why need explicit left outer join
s. should sufficient.
select mutual_fund_name, concat(contact_first_name,' ',contact_last_name) mutual_fund mf left join mutual_fund_has_contact mfhc on mf.mutual_fund_id = mfhc.mutual_fund_id left join contact c on c.contact_id = mfhc.contact_id left join institution on i.institution_id = ihmf.institution_id left join institution_has_mutual_fund ihmf on ihmf.mutual_fund_id = mf.mutual_fund_id mf.mutual_fund_name in ('vanguard balanced index fund', 'vanguard consumer discretionary index fund', 'vanguard extended market index fund', 'vanguard growth index fund') order mutual_fund_name;
Comments
Post a Comment