当前位置:网站首页>MySQL queries difference sets (missing data) by linking tables based on an associated field

MySQL queries difference sets (missing data) by linking tables based on an associated field

2022-06-13 08:19:00 Parthenocissus still works

Occasionally encountered some exceptions in the development process , Need to verify data integrity , See if some related data is missing , for example :

user:

        

profile:

  Above two tables ,user adopt profile_id relation profile Medium id, At the same time, the two tables do not use foreign key Association , When an exception occurs in the program , Or when the business logic is not mandatory , There could be profile Missing data in , It is not easy to view when the amount of data is large ,

At this time, you can find the missing... Through the linked table query profile Corresponding to the data user The data of :

SELECT u.id,u.name,p.age,p.gender,p.height FROM `user` u LEFT JOIN `profile` p ON u.profile_id=p.id WHERE ISNULL(p.id)

  give the result as follows :

  Sometimes data query and correction can be done with .

原网站

版权声明
本文为[Parthenocissus still works]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270544564023.html