我正在使用下面的代码,但没有得到任何结果,请任何人给我一个建议。
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
最佳答案
要从users_register
表中获取不匹配的记录,您可以在WHERE<中使用
子句。 LEFT JOIN
和列名IS NULL
/
这就是你所期待的
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
关于mysql - 如何从12个表中获取不匹配的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38117328/