我有 2 张桌子:
TABLE customer_service_provider
==================================
id | customer | service_provider
==================================
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 2 | 1
5 | 2 | 2
6 | 3 | 1
7 | 4 | 1
8 | 4 | 2
9 | 4 | 3
===================================
TABLE service_provider
======================
id | Name
======================
1 | Company1
2 | Company2
3 | Company3
======================
我需要从表customer_service_provider(字段customer和service_provider)中获取service_provider不存在于表customer_service_provider中但存在于service_provider表中的信息。
结果应如下所示:
customer | service_provider
==============================
2 | 3
3 | 2
3 | 3
==============================
解决了:
选择
不同的 sp.id,
csp.customer
从
service_provider sp,
customer_service_provider csp
在哪里
sp.id 不在(选择 csp2.service_provider
FROM customer_service_provider csp2
其中 csp2.customer = csp.customer)