join - What is the difference between these two MySQL queries? -


select count( companyid ) companies  left join cities on cities.cityid = companies.cityid group companies.companyid; 

vs

select count( companyid ) cities  left join companies on cities.cityid = companies.cityid group companies.companyid; 

what difference?

in first query left table companies , in second query cities.

the left join keyword returns rows left table (table_name1), if there no matches in right table (table_name2).

first query

the left join keyword returns rows companies table , if there no matches in cities table

second query

the left join keyword returns rows cities table , if there no matches in companies table

visual representation of sql joins


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -