如何在sql中合并两个不同的select查询

时间:2014-06-13 09:47:43

标签: mysql

第一次查询:

SELECT orders.order_id,account.username 
    FROM account 
      LEFT JOIN orders ON orders.account_id=account.account_id

第二次查询:

SELECT items.item_name 
   FROM order_items 
   LEFT JOIN items ON items.item_id=order_items.item_id

2 个答案:

答案 0 :(得分:0)

试试这个

SELECT 
       orders.order_id,
       account.username,
       items.item_name
FROM account 
     LEFT JOIN orders ON orders.account_id=account.account_id
     LEFT JOIN order_items ON orders.order_id = order_items.order_id
     LEFT JOIN items ON items.item_id=order_items.item_id

答案 1 :(得分:0)

试试这个

SELECT orders.order_id,account.username, items.item_name 
FROM account 
LEFT JOIN orders on orders.account_id=account.account_id
left join order_items ON orders.order_id = order_items.order_id
left join items on items.item_id=order_items.item_id