0
表1 - 具有表2 &表3获取表数据不包括约束
表2
表3
- 的任何数据,其存在于与约束表1与表2 & 3是有效的数据的约束。
- 通过手动关闭约束,某些虚假数据以某种方式进入table1。
- 我想收集那些仅存在于table1中的数据,没有任何限制。
是否有一种简单的方法来获取mysql中没有约束数据的table1数据?
谢谢。
表1 - 具有表2 &表3获取表数据不包括约束
表2
表3
是否有一种简单的方法来获取mysql中没有约束数据的table1数据?
谢谢。
如果我明白你的问题,你正在寻找父表中的失踪或假记录。我将想象table2和table3中的约束字段是id
,而table1中的fk字段是table2_id
和table3_id
。如果是这种情况,您将查询缺失的连接:
SELECT t1.id, t1.table2_id, t1.table3_id FROM table1 t1
LEFT JOIN table2 t2 ON t2.id = t1.table2_id
LEFT JOIN table3 t3 ON t3.id = t1.table3_id
WHERE t1.table2_id IS NULL
OR t1.table3_id IS NULL;