mysql - trying to link address table with companyX -
i have question related mysql relationships. let's have 4 table companya companyb companyc , companyd, each containing 3 columns: name
, phone
, , age
. have table called address want link each companyx address table , let’s if did select * companyx;
address column should appearnext each name.
can done mysql?
first of all, if company tables have exact same structure why don't use single table store information? may want read database normalization.
secondly create relation table named 'companiesaddresses' , store fields such "companyid" , "addressid" in (you have create primary key column in companyx's table , same in 'addresses' table use inner join clause information want such select companyx.companyname, addresses.address companyx inner join companiesaddresses on companyx.companyid = companiesaddresses.companyid inner join addresses on companiesaddresses.addressid = addresses.addressid
.
i hope understood want correctly.
Comments
Post a Comment