-3

I have Three Tables

Table 1       Table 2                 Table 3
id   deg       id  t1_id   name       id  t2_id  t1_id   name
101  ABC       1   202   Test 1        1   3      202    Job a
202  PQR       2   202   Test 2        2   1      101    Job b
303  XYZ       3   101   Test 3        3   2      303    job C

How write a single MySql query so that i can achieve results as Follows:

t1_name  t1_deg  t2_name t2_deg 
Test 1    PQR     Job b   ABC
Test 2    PQR     Job c   XYZ
Test 3    ABC     Job a   PQR

Thanks For Help
2

1 Answer 1

0
    SELECT
    Table2.name,
    Table1.deg,
    Table3.name
FROM
    Table1
JOIN 
    Table2 ON Table2.t1_id = Table1.id
JOIN 
    Table3 ON Table1.id = Table3.t1_id;
7
  • I would expect the answer to have the same number of columns as the question.
    – Strawberry
    Commented May 25, 2018 at 9:28
  • This is good but I want table 1 deg for both my table not just one
    – Rahul
    Commented May 25, 2018 at 9:29
  • This is missing one column
    – Rahul
    Commented May 25, 2018 at 9:30
  • can you explain where t2_deg is come from. because what I see is only one deg column Commented May 25, 2018 at 9:32
  • Table 1 contain a deg column which is refereed in both table 2 and table 3 i want separate deg value according to their id fro both table one deg value from table 1 and another deg value for table 2 respectively
    – Rahul
    Commented May 25, 2018 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.