By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

Joining three tables at a time and get the required output

P: 22
Hai all,

I have three tables in MySql.Each table is related with 'id' column.
First table contains all the id's.
Second contains some of id's of first table and third table contains remaining id's of the first table.
As shown in the below 3 figures.

Based on that i want the output as shown in the figure 4(OutPut).

How i get my required Output by using the Join's.Please send me the code,so that it is very helpful for me.

Thanks In Advance,
Phani Kumar Ch.
Attached Images
File Type: jpg 1.jpg (3.9 KB, 62 views)
File Type: jpg 2.jpg (2.2 KB, 48 views)
File Type: jpg 3.jpg (2.9 KB, 36 views)
File Type: jpg OutPut.jpg (5.9 KB, 40 views)
May 11 '14 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,035
Expand|Select|Wrap|Line Numbers
  1. SELECT t1.id, t1.title, t1.description
  2.        x.impact, x.urgency, x.priority
  3. FROM table1 t1
  4. LEFT JOIN (SELECT id, impact, urgency, priority
  5.            FROM table2 t2 
  6.            UNION ALL
  7.            SELECT id, impact, urgency, priority
  8.            FROM table3 t3)X on X.id=t1.id 
  9.  
The 'LEFT JOIN' can be a 'INNER JOIN' here too, because all id's are there, but they might not all so i choose to write LEFT JOIN

I also left out the second 'id' column.... ;)
May 11 '14 #2

P: 22
Thank you Luuk.

what you sended me that is very helpful for me.
and i want to know one thing that is if my second and third tables also contains the extra column which are non match.
For example in table 2 column 'product' is there but not in the third table, similarly in the third table column 'origin' is there but not present in the second table.

so how to add these two columns also in my output.could you please tell me how can i do this.

Thanks In Advance,
Phani Kumar Ch.
May 12 '14 #3

Expert 100+
P: 1,035
Sorry i don't understand your English.....
May 12 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.