I have 5 tables in my Mysql database with t1 with field name like data,id,cool and 4 other tables with id and data say t2,t3,t4,t5.
I have used join and sub queries but result i am getting is empty set its not mandatory that all the fields in the t2,t3,t4,t5 tables are populated .t4,t5,t3,t2 can be empty i am using where clause on data if data column of t1 = t2 = t3 = t4 = t5 if it finds any matching data in any of the table it prints the cool from t1 and id and data from found table if any and if founds the data match in all the table it prints all the table stats like
cool data.t1 id.t1
cool data.t2 id.t2
and so on
table t1
cool data id
0 xyz 1
table t2
data id
xyz 5
table t3
data id
xyz 4
table t4
data id
xyz 3
table t5
data id
xyz 2
desired output
cool data id
0 xyz 1
0 xyz 4
0 xyz 3
0 xyz 5
0 xyz 2
if any of the table is empty say t5 and t4 than output should be
cool data id
0 xyz 1
0 xyz 4
0 xyz 3
What i understand from the question is you need to get data from table
t1for all other tables for all matchingdataandidcolumn in respective table.A simple way to achieve is to join each table with
t1seperately and then useunion allto combine all results.as from your example, it is quite possible that there can be duplicate records To filter them out use distinct like this –