Simple join in postgresql I have a simple join query below :

select jobs.location_id 
from companies, 
     jobs 
where jobs.company_id = companies.id 
and companies.name = 'name';


it doesn't seem to get the job location of company has that name, but somehow all location_id in jobs table.

Meanwhile these two separate queries do the job:

select id from companies where name = 'name';
select jobs.location_id from jobs where jobs.company_id = [resulted id from query above];


What's wrong with the first query ?
Don't join tables like that. Using a comma means cross joining tables (cartesian product).

select j.location_id 
from companies c 
   join jobs j on j.company_id = c.id
and c.name = 'name'


These two queries should produce the same execution plan and therefore the same results but this one is much clearer.