Skip to content

Instantly share code, notes, and snippets.

@Arakaki
Last active December 28, 2015 02:48
Show Gist options
  • Save Arakaki/7430092 to your computer and use it in GitHub Desktop.
Save Arakaki/7430092 to your computer and use it in GitHub Desktop.
MySQLだと上手くJoinできない

##環境 MySQL 5.5.20

##SQL //NG select m.id as i_on_m, m.name as n_on_m, m.company_id as ci_on_m , cnt.id as i_on_cnt, cnt.name as n_on_cnt , cmp.id as i_on_cmp, cmp.name as n_on_cmp, cmp.country_id as ci_on_cmp from members m inner join countries cnt on cmp.country_id = cnt.id left join companies cmp on m.company_id = cmp.id order by m.id //OK select m.id as i_on_m, m.name as n_on_m, m.company_id as ci_on_m , cnt.id as i_on_cnt, cnt.name as n_on_cnt , cmp.id as i_on_cmp, cmp.name as n_on_cmp, cmp.country_id as ci_on_cmp from members m left join companies cmp on m.company_id = cmp.id inner join countries cnt on cmp.country_id = cnt.id order by m.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment