為了使其理解,我們正在使用以下表中的資料−
mysql> Select * from customers; +-------------+----------+ | Customer_Id | Name | +-------------+----------+ | 1 | Rahul | | 2 | Yashpal | | 3 | Gaurav | | 4 | Virender | +-------------+----------+ 4 rows in set (0.00 sec) mysql> Select * from reserve; +------+------------+ | ID | Day | +------+------------+ | 1 | 2017-12-30 | | 2 | 2017-12-28 | | 2 | 2017-12-25 | | 1 | 2017-12-24 | | 3 | 2017-12-26 | +------+------------+ 5 rows in set (0.00 sec)
現在,以下是子查詢,將找到所有沒有預訂任何汽車的客戶的姓名。
mysql> Select Name from customers where customer_id NOT IN (Select id From reserve); +----------+ | Name | +----------+ | Virender | +----------+ 1 row in set (0.00 sec)
現在,透過以下步驟,我們可以將上述子查詢轉換為RIGHT JOIN −
mysql> SELECT Name from customers LEFT JOIN reserve ON customer_id = Id WHERE Id IS NULL; +----------+ | Name | +----------+ | Virender | +----------+ 1 row in set (0.00 sec)
以上是我們如何將子查詢轉換為左連接?的詳細內容。更多資訊請關注PHP中文網其他相關文章!