我有如下2個表:檢索所有沒有登錄用戶從MySQL表(SQL查詢)
+-------------+-----------+--------------+-------------------------------+
| v3_customer |
+-------------+-----------+--------------+-------------------------------+
| customer_id | firstname | lastname | email |
+-------------+-----------+--------------+-------------------------------+
| 1 | Piet | Pizza | [email protected] |
| 2 | Klaas | Hein | [email protected] |
| 3 | Henk | Crowdcontrol | [email protected] |
+-------------+-----------+--------------+-------------------------------+
+-------------+-------------+---------------+
| v3_customer_activity |
+-------------+-------------+---------------+
| activity_id | customer_id | key |
+-------------+-------------+---------------+
| 1 | 1 | login |
| 2 | 1 | order_account |
| 3 | 2 | login |
+-------------+-------------+---------------+
我要的是選擇已經沒有登錄的所有客戶(注意登錄鍵v3_customer_activity
)。所以在這種情況下,這將是客戶customer_id:3
我正在使用mysql數據庫。
我曾嘗試使用下面的查詢嘗試:
SELECT DISTINCT v3_customer.customer_id, v3_customer.firstname, v3_customer.lastname, v3_customer.email FROM `v3_customer` JOIN v3_customer_activity ON v3_customer.customer_id = v3_customer_activity.customer_id WHERE v3_customer.customer_id != (SELECT v3_customer_activity.customer_id FROM v3_customer_activity)
在此希望它會在子查詢中發現的行之間循環。 這導致了一個錯誤,告訴我一個子查詢可能不包含多行。
TL; DR
我想要的是檢索v3_customer
每一個客戶誰不是在表v3_customer_activity
非常感謝:D! – Baklap4
我不知道v3_customer。*是有效的mysql,你知道的越多! – Baklap4
@ Baklap4:沒有憂慮。我的榮幸 :) –