mysql inner join same table and same column multiple times from multiple tables -
i'm having issue mysql query search screen @ work. i've got query working using code i'll post below, i'm suspicious there better way it. mysql pretty newbie really, figure out go along, or try to.
here concept of database: there entity, address, contact, client, group , facility table involved in query.
each client, group , facility "entity" lack of better word. each entity has it's own entity id in entity table.
the entity table houses address record id , contact record id.
on facility search screen, if user searches phone number want search through client , group records facility records. , return matching facility information would.
here's i've got far(i'm doing nothing address outside of facility records yet , i've hardcoded things sake of explaining myself):
select facility.facilityid, facility.name, contact.phonenumber, addy.state addy.zipcode, facility.productionfacilityid, facility.productionentityid facility facility inner join clientgroup cg on facility.groupid = cg.groupid inner join client c on cg.clientid = c.clientid inner join entity e on facility.facilityid = e.entityid inner join entity eg on cg.groupid = eg.entityid inner join entity ec on c.clientid = ec.entityid inner join contact contact on e.billingcontactid = contact.contactid inner join contact contactg on eg.billingcontactid = contactg.contactid inner join contact cc on ec.billingcontactid = cc.contactid inner join address addy on addy.addressid = e.physicaladdressid (facility.facilityid '%$searchfor%' or contactg.phonenumber '%$searchfor%' or cc.phonenumber '%$searchfor%') , facility.isrowactive=1 order $searchtype";
thanks in advance help!
yes, better way maintenance purposes create view of inner joins , querying view. remember in terms of performance there little way of improvement maintenance of code become easier.
given purpose inner joins not entirely avoidable unless decide change structure of tables
Comments
Post a Comment