查找不匹配的记录 [英] Find unmatched records

查看:38
本文介绍了查找不匹配的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个mysql问题.我有两个表,一个称为表单,另一个是记录.记录是每个表格的记录.我可以将多个记录与一个表单 ID 关联.但是,并非所有表单都有与之关联的记录.我想找到所有没有记录的表单.

This is a mysql question. I have two tables one called forms and the other records. The records are a record for each form. I can have multiple records associate with a form id. However not all forms have a record associated with. I want to find all forms that do not have a record.

我能做的最好的就是这个

The best I could do is this

SELECT * 
FROM forms
JOIN records WHERE forms.form_id != records.form_id

但是我最终得到了一百万多条记录,我知道这是不正确的.

However I end up with a million plus records and I know that is not correct.

推荐答案

尝试LEFT OUTER JOIN:

SELECT * FROM forms 
LEFT OUTER JOIN records
ON forms.form_id = records.form_id
WHERE records.form_id IS null

这篇关于查找不匹配的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆