我有2個表訂單和客戶數據爲:內/外連接問題在MySQL
mysql> select * from orders;
+---------+----------------+----------+-------+
| orderid | product | customer | price |
+---------+----------------+----------+-------+
| 292 | sofa | 101 | 6000 |
| 293 | table | 105 | 3000 |
| 294 | table | 104 | 1450 |
| 295 | table | 101 | 1200 |
| 296 | chair | 103 | 800 |
| 297 | dressing table | 104 | 9000 |
| 298 | corner | 102 | 1000 |
| 299 | corner | 102 | 900 |
| 300 | bed | NULL | NULL |
| 301 | door | NULL | NULL |
+---------+----------------+----------+-------+
10 rows in set (0.00 sec)
mysql> select * from customers;
+--------+----------+-----------+
| custid | name | location |
+--------+----------+-----------+
| 101 | jaspreet | New delhi |
| 102 | harpreet | Jalandhr |
| 103 | surjit | Amritsar |
| 104 | harneet | ludhiana |
| 105 | hashar | New Delhi |
| 106 | harneet | NULL |
+--------+----------+-----------+
6 rows in set (0.00 sec)
當我運行內部聯接,它返回以下數據:
mysql> select orders.orderid,customers.name from orders inner join customers where orders.customer=customers.custid;
+---------+----------+
| orderid | name |
+---------+----------+
| 292 | jaspreet |
| 295 | jaspreet |
| 298 | harpreet |
| 299 | harpreet |
| 296 | surjit |
| 294 | harneet |
| 297 | harneet |
| 293 | hashar |
+---------+----------+
8 rows in set (0.00 sec)
但外連接不在這方面工作。
mysql> select orders.orderid,customers.name from orders left join customers where orders.customer=customers.custid;
ERROR 1064(42000):你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法 使用正耳朵「其中orders.customer = customers.custid」在行1
有人可以幫我這個概念 手冊?
在此先感謝
明確使用'加入'關鍵字需要'關於'關鍵字來代替'哪裏' – Rugal