sql - MySQL: Multi-column join on several tables -


i have several tables joining need add table , can't seem right query. here have -

table 1
carid, catid, makeid, modelid, caryear

table 2
makeid, makename

table 3
modelid, modelname

table 4
catid, catname

the query using join these is:

select * table1   join table2 b on a.makeid=b.makeid   join table3 c on a.modelid=c.modelid   join table4 d on a.catid=d.catid   a.carid = $carid; 

now need add 5th table getting 3rd party having hard time adding existing query. new table has these fields -

table 5 id, year, make, model, citympg, hwympg

i need citympg , hwympg based on caryear table 1, makename table 2, , modelname table 3. know can second query values, prefer single query , have of data in single row. can done in single query? if so, how?

it's possible have more condition in join. work?

select a.*, e.citympg, e.hwympg table1   join table2 b on a.makeid=b.makeid   join table3 c on a.modelid=c.modelid   join table4 d on a.catid=d.catid   join table5 e on b.makename = e.make                 , c.modelname = e.model                 , a.caryear = e.year   a.carid = $carid; 

...though question not clear. did only want join table5 others, or there else wanted table5?


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -