I have 2 tables which I want to join, and I can achieve it by 2 ways:
Customers:
+------------+--------------------+--------------------+--------------+
| CustomerID | Name | Address | City |
+------------+--------------------+--------------------+--------------+
| 1 | Julie Smith | 25 Oak Street | Airport West |
| 2 | Alan Wong | 1/47 Haines Avenue | Box Hill |
| 3 | Michelle Arthur | 357 North Road | Yarraville |
| 4 | Geogrge Napolitano | 177 Melbourne Road | Coburg |
+------------+--------------------+--------------------+--------------+
Orders:
+---------+------------+--------+------------+
| OrderID | CustomerID | Amount | Date |
+---------+------------+--------+------------+
| 1 | 3 | 69.98 | 2019-04-02 |
| 2 | 1 | 49.99 | 2019-04-15 |
| 3 | 2 | 74.99 | 2019-05-19 |
| 4 | 3 | 24.99 | 2019-05-01 |
+---------+------------+--------+------------+
Now I would like to select only those customers, that has no order placed (OrderID == null
). That is only the Geogrge Napolitano
. So I can use 2 ways:
mysql> select Customers.CustomerID, Customers.Name
-> from Customers left join Orders
-> on Customers.CustomerID = Orders.CustomerID
-> where Orders.OrderID is null;
or
mysql> select Customers.CustomerID, Customers.Name
-> from Customers left join Orders
-> using(CustomerID)
-> where Orders.OrderID is null;
Now for me. It seems that =
in first case (Customers.CustomerID = Orders.CustomerID
), is exactly the same as USING()
that Id. But is it always that case? In what other cases I can use the mysql function USING()
?