我正在使用下面的代码,但我没有得到任何结果,请任何人都可以给我一个建议。
users_register
表包含所有用户的手机号码,我有12个表格,如property
,hostels
,hotels
等等。
如何获得不匹配的手机号码
SELECT t1.user_mobileno,
t1.user_fullname
FROM users_register t1
LEFT JOIN userpostproperties t2 ON t1.user_mobileno = t2.property_contact_number
LEFT JOIN services t3 ON t1.user_mobileno=t3.contact_num
LEFT JOIN hostels t4 ON t1.user_mobileno=t4.h_contact_num
LEFT JOIN sales t5 ON t1.user_mobileno=t5.sales_contact
LEFT JOIN rentals t6 ON t1.user_mobileno=t6.rental_mobile
LEFT JOIN jobs t7 ON t1.user_mobileno=t7.emp_mobile
LEFT JOIN healthcare t8 ON t1.user_mobileno=t8.contact_num
LEFT JOIN education t9 ON t1.user_mobileno=t9.edu_mobile
LEFT JOIN hotels t10 ON t1.user_mobileno=t10.contact_num
LEFT JOIN restaurant t11 ON t1.user_mobileno=t11.contact_num
LEFT JOIN finance t12 ON t1.user_mobileno=t12.contact_no
LEFT JOIN manufacturer t15 ON t1.user_mobileno=t15.contact_no
答案 0 :(得分:1)
要从users_register
表中获取不匹配的记录,您可以在LEFT JOIN
子句中使用IS NULL
列名为WHERE
的{{1}}。
这是你期待的吗?
SELECT t1.user_mobileno,
t1.user_fullname
FROM users_register t1
LEFT JOIN userpostproperties t2 ON t1.user_mobileno = t2.property_contact_number
LEFT JOIN `services` t3 ON t1.user_mobileno = t3.contact_num
LEFT JOIN hostels t4 ON t1.user_mobileno = t4.h_contact_num
LEFT JOIN sales t5 ON t1.user_mobileno = t5.sales_contact
LEFT JOIN rentals t6 ON t1.user_mobileno = t6.rental_mobile
LEFT JOIN jobs t7 ON t1.user_mobileno = t7.emp_mobile
LEFT JOIN healthcare t8 ON t1.user_mobileno = t8.contact_num
LEFT JOIN education t9 ON t1.user_mobileno = t9.edu_mobile
LEFT JOIN hotels t10 ON t1.user_mobileno = t10.contact_num
LEFT JOIN restaurant t11 ON t1.user_mobileno = t11.contact_num
LEFT JOIN finance t12 ON t1.user_mobileno = t12.contact_no
LEFT JOIN manufacturer t15 ON t1.user_mobileno = t15.contact_no
WHERE t2.property_contact_number IS NULL AND
t3.contact_num IS NULL AND
t4.contact_num IS NULL AND
t5.sales_contact IS NULL AND
t6.rental_mobile IS NULL AND
t7.emp_mobile IS NULL AND
t8.contact_num IS NULL AND
t9.edu_mobile IS NULL AND
t10.contact_num IS NULL AND
t11.contact_num IS NULL AND
t12.contact_no IS NULL AND
t15.contact_no IS NULL