mysql - Filter on the Many side of a One-To-Many Relationship -
mysql - Filter on the Many side of a One-To-Many Relationship -
i've got 2 tables: jobs , job_industries (joined on jobs.id=job_industries.job_id
). i'd find every job jobs.title '%finance%'
, without job_industries.industry=1
.
however, when running query below, i'm getting list of every job matches title criteria , has @ to the lowest degree 1 industry alternative isn't 1
.
select jobs.id, title, industry `job_industries` left bring together jobs on jobs.id=`job_industries`.job_id is_live=1 , jobs.`is_closed`=0 , 1 in (select industry job_industries job_id in )
e.g. if job has 2 job_industry relations (industry=1
, industry=2
), job match query. i'd prefer find jobs don't.
select j.id, j.title, ji.industry jobs j inner bring together job_industries ji on j.id = ji.job_id , ji.industry <> 1 j.title '%finance%' , j.is_live = 1 , j.is_closed = 0 , not exists (select 1 job_industries ji2 ji2.job_id = j.id , ji2.industry = 1);
alternatively, instead:
select j.id, j.title, ji.industry jobs j inner bring together job_industries ji on j.id = ji.job_id , ji.industry <> 1 left bring together job_industries ji2 on j.id = ji2.job_id , ji2.industry = 1 j.title '%finance%' , j.is_live = 1 , j.is_closed = 0 , ji2.job_id null;
mysql sql one-to-many
Comments
Post a Comment