php - Multiple meta key and meta value search -
i working on client project , stumped upon multiple meta_key, meta value search.
my db structure that
clinics clinics_meta ======= ============= id name id fk_clinic_id meta_key meta_value 1 dental 1 1 city london 2 heart 2 1 country england 3 2 city manchester 4 2 country london
i want clinic city = london
, country = england
i tried
select distinct(clinics.id) clinics, clinic_meta clinics.id = clinic_meta.fkclinicid , (clinic_meta.metakey = 'cliniccountry' , clinic_meta.metavalue '%england%') , (clinic_meta.metakey = 'cliniccity' , clinic_meta.metavalue '%london%')
please dont conside syntax error logic.
this code not return clinic name/id
,
but instead of using 2 filter city,country
if use 1 filter return clinic name.
any appreciated.
thanks.
select cl.* clinics cl inner join clinics_meta cm1 on cl.id=cm.clinic_id inner join clinics_meta cm2 on cm1.clinic_id=cm2.clinic_id cm1.meta_key='country' , cm1.meta_value='england' , cm1.meta_key='city' , cm2.meta_value='london' group t1.id;
Comments
Post a Comment