我有3個表,其中一個帳戶,朋友的一個又一個消費者之間存在的。 事情是這樣的:檢查值是否存在,而不是2個表
table_accounts
id | account_name
table_friends
id | account_id | people_id
table_consumers
id | account_id | people_id
我需要跨越以下信息:
其中consumer_id兩個表中並存,簡單的東西是這樣的:
SELECT
*
FROM
table_friends,
table_consumers
WHERE
table_friend.account_id = 12345
AND table_friend.account_id = table_consumers.account_id
GROUP BY table_friend.people_id
這個查詢是很慢的
好了,我現在需要得到什麼是consumer_id的朋友表,這是不是在消費者表。而在第三個瞬間,找出哪些consumer_id不會在朋友表中存在。但我認爲這是同樣的事情...
我的疑問是關於邏輯,我想不出如何跨越這一信息。
我不明白你的數據庫模式,你最後的§不清楚你想要什麼,請編輯你想要的字段名稱和表之間的關係 – Blag