本文介绍了sql查询选择不在另一个表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想要一个select查询,它比较两个不同的本地数据库的两个表,并返回第二个表中不存在的一个表的值,试过这个但是有错误 声明 library.dbo.phones as t1 选择 * 来自 [library] .dbo.table_1 as t2 其中 t2.onoma 不 喜欢 t1.name 或者这个 声明 library.dbo.phones as t1 select * 来自 [library] .dbo.table_1 as t2 其中 t2.onoma 不 t1.name 解决方案 使用不存在 [ ^ ] 一个例子: 选择 * 来自 [databasename] .dbo.table1 t1 其中 不 存在 ( [databasename] .dbo.table2 t2 其中 t1.name = t2.onoma ) 是的,你可以使用不在 选择 * 来自 [databasename] .dbo.table1 where 列 不 in (选择 列 来自 [databasename] .dbo.table2) I want to have a select query which compares 2 tables of different both local databases and return the values of one table where they are not exists in second table, tried this but there are errorsdeclare library.dbo.phones as t1 select * from [library].dbo.table_1 as t2 where t2.onoma Not like t1.nameor thisdeclare library.dbo.phones as t1 select * from [library].dbo.table_1 as t2 where t2.onoma Not in t1.name 解决方案 Use Not Exists[^]An example:select * from [databasename].dbo.table1 t1 wherenot exists(select * from [databasename].dbo.table2 t2 where t1.name = t2.onoma)Yeah, you can use Not inselect * From [databasename].dbo.table1 where Column not in(select column from [databasename].dbo.table2 ) 这篇关于sql查询选择不在另一个表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-21 00:32
查看更多