posted 6 months ago
I have a table TableA with 6 columns(col1,col2,col3,col4,col5,col6) and there is an other table TableB with 5 columns (colA, ColB(typeID), ColC, ColD, ColE). I need to fetch the col2 ...Col6 from tableA by joining with TableB. I would have to
join col2 from TableA with colB from TableB and again
join col3 from TableA with colB from TableB
join col4 from TableA with colB from TableB
join col5 from TableA with colB from TableB
Each of the column from TableA needs to be joined with same column (colB) in TableB.Here the typeid value will be different for each of the col types in TableAe The colB is a type id and hence col2, col3,col4, col5 are different types, hence they are kind being joined with colb. I need a query which will fetch all the values of col2, col3,col4, col5 and the colc value based on each type in the same query. I tried writing the query. But could not fetch all the values in a single query.I need to fetch the values for all the field in TableA using a single Query.
To fetch the associated value for col3, i need to write the below query
similarly for col4 the below query
Is there a way I can use a single query to fetch all the 3 col values. I know we can use union function and join the above three queries. But I wanted to know if there is a single query that I can use i.e
In the above case, joining the fields seems to be an issue.
Any help on this is much appreciated.