这似乎是一个简单的问题,但我正在比较一个包含随机表和列与syscolumns
的表此查询将为我提供缺少的列
select object_name(syscolumns.id) , syscolumns.name
from syscolumns
where not exists
(select 1
from CHECKINGTABLE
where object_name(CHECKINGTABLE.id) = object_name(syscolumns.id)
and CHECKINGTABLE.name=syscolumns.name)
and object_name(syscolumns.id) ='TAB1'
但是这样会给我错误的结果
select object_name(syscolumns.id) , syscolumns.name
from syscolumns , CHECKINGTABLE
where not exists
(select 1
from CHECKINGTABLE
where object_name(CHECKINGTABLE.id) = object_name(syscolumns.id)
and CHECKINGTABLE.name=syscolumns.name)
and object_name(syscolumns.id) =object_name(CHECKINGTABLE.id)
我做错了什么?我想要一个查询来比较我拥有的表和syscolumns,以识别我的表中缺少的数据
答案 0 :(得分:0)
您可以尝试以下方法。我手边没有ASE DB,但希望语法正确。
SELECT syscolumns.id , syscolumns.name
FROM syscolumns LEFT OUTER JOIN CHECKINGTABLE
ON (CHECKINGTABLE.id = syscolumns.id
AND CHECKINGTABLE.name=syscolumns.name)
WHERE CHECKINGTABLE.name IS NULL