-4

Here No related tables between

Table1:

id | title   | amount | 
-----------------------
 1 | Task1   | 30     | 
 2 | Task2   | 20     | 
 3 | Task2   | 40     | 
 4 | Task2   | 10     | 
 5 | Task2   | 30     | 

Table2:

id | name   | total | 
---------------------
 7  | name1  | 30    | 
 8  | name2  | 20    | 
 9  | name3  | 40    | 
 10 | name4  | 10    | 
 11 | name5  | 30    | 

Table3:

id | name   | total_count | 
---------------------------
 20 | name1  | 10          | 
 21 | name2  | 22          | 
 22 | name3  | 33          | 
 23 | name4  | 23          | 
 24 | name5  | 42          |
 25 | name6  | 90          |
 26 | name7  | 85          |

Select from each Tables per two columns, Please help, Sorry my English is bad, Anybody help, I need the result follow:

Result:

t1_title | t1_amount | t2_name | t2_total | t3_name | t3_total |
----------------------------------------------------------------
 Task1   | 30        | name1   | 30       | name1   | 10       |
 Task2   | 20        | name2   | 20       | name2   | 22       |
 Task3   | 40        | name3   | 40       | name3   | 33       |
 Task4   | 10        | name4   | 10       | name4   | 23       |
 Task5   | 30        | name5   | 30       | name5   | 42       |
         | 0         |         | 0        | name6   | 90       |
         | 0         |         | 0        | name7   | 87       |

Here no Related (relationship) between tables.

Thanks!!!

Dharman
  • 30,962
  • 25
  • 85
  • 135
KorozCo
  • 169
  • 1
  • 1
  • 9
  • 2
    See: [Why should I provide an MCVE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query) – Strawberry Dec 12 '18 at 17:31
  • 1
    Is the `id` column related between the tables? – Shidersz Dec 12 '18 at 17:31
  • 2
    So is this mysql or postgres? – 404 Dec 12 '18 at 17:32
  • Show us what you've tried so far. And you have to tell us how the tables are related. Based on what you've showed, they aren't. – Andrew Dec 12 '18 at 17:37
  • 1
    Possible duplicate of [How to do a FULL OUTER JOIN in MySQL?](https://stackoverflow.com/questions/4796872/how-to-do-a-full-outer-join-in-mysql) – Andrew Dec 12 '18 at 17:38
  • What you want is a FULL OUTER JOIN, those don't exist in mySql, they're TSQL syntax, but they can be emulated by doing left and right outer joins. – Andrew Dec 12 '18 at 17:39
  • 2
    The result set is nonsensical (in relation to the data set). – Strawberry Dec 12 '18 at 17:41

1 Answers1

1

It looks like you want the equivalent of a FULL OUTER JOIN between the three tables, which I believe would need to achieved using a UNION of three queries, e.g.:

select t1.title, t1.amount, t2.name, t2.total, t3.name, t3.total_count
from t1 left join t2 on t1.id = t2.id left join t3 on t1.id = t3.id
union 
select t1.title, t1.amount, t2.name, t2.total, t3.name, t3.total_count
from t2 left join t1 on t2.id = t1.id left join t3 on t2.id = t3.id
union
select t1.title, t1.amount, t2.name, t2.total, t3.name, t3.total_count
from t3 left join t1 on t3.id = t1.id left join t2 on t3.id = t2.id
Lee Mac
  • 15,615
  • 6
  • 32
  • 80