Sql joins two tables, one summary is another detail

When joining two tables, I'm not sure how to join the following tables in what I wanted.

Table a:

--------------------------------------
| id | name | buy time | total |
--------------------------------------
| 1 | A | 3 | 30 |
--------------------------------------
| 2 | B | 1 | 10 |
--------------------------------------

Table B:

-------------------------------
| id | orderid | price |
-------------------------------
| 1 | 1 | 10 |
-------------------------------
| 1 | 2 | 10 |
-------------------------------
| 1 | 3 | 10 |
-------------------------------
| 2 | 4 | 10 |
-------------------------------

Join table C

-------------------------------------------------- -------
| id | name | buy time | total | orderid | price |
-------------------------------------------------- -------
|   1 |    A   |     3     |    30  |          |        |
---------------------------------------------------------
|   1 |        |           |        |    1     |   10   |
---------------------------------------------------------
|   1 |        |           |        |    2     |   10   |
---------------------------------------------------------
|   1 |        |           |        |    3     |   10   |
---------------------------------------------------------
|   2 |    B   |     1     |    10  |          |        |
---------------------------------------------------------
|   2 |        |           |        |    4     |   10   |
---------------------------------------------------------

"Left OUT JOIN A.id = B.id" , .

" 0 B", 0, , .

, ?

+4
4

, , UNION :

SELECT id, name, `buy time`, total, null AS orderid, null AS price
FROM A

UNION 

SELECT id, null, null, null, orderid, price
FROM B
ORDER BY id, name DESC, orderid

+3

, UNION ALL:

SELECT `id`,`name`,`buy time`,`total`,null,null
FROM TableA 
UNION ALL
SELECT id,null,null,null,orderid,price
FROM TableB 
ORDER BY `id`,`name` ,orderid

, - .

+1

it looks like you need to use UNION

select id, name, `buy time`, total, null AS orderid, null AS price
from A
UNION 
select id, null, null, null, orderid, price
from B
order by id, name DESC
0
source

select ID, name, purchase time, total quantity, order, price from (

  SELECT  [id]
 , null as [orderid]
  ,null as [price],
   [name]
  ,[buytime]
  ,[total]
   FROM A
     UNION

 SELECT [id]
  ,[orderid]
  ,[price],
  null as[name]
  , null as[buytime]
  ,null as [total]
 FROM B

) like aa

0
source

All Articles