简体   繁体   English

SQL比较,其中在表2中找不到表1的值,并将结果显示为表3

[英]Sql Comparison where values of Table1 not found in Table2 and showing result as Table3

I was trying someting like: 我正在尝试类似的东西:

Select Items 
From Table1 
Where Not Exists (
    Select Items 
    From Table2 
    Where Table2.Items = Table1.Items) As Table3.Items

but somehow not working so can anywone tell me how can i achive this? 但是以某种方式无法正常工作,所以有人可以告诉我如何实现这一目标吗?

If you want to create a new table with this results, you can try this: 如果要使用此结果创建新表,可以尝试以下操作:

Select Items 
Into Table3
From Table1 
Where Not Exists (Select Items From Table2 Where Table2.Items = Table1.Items) 

If you're looking for rows in t3 that do exist in t1 but not in t2 , try: 如果您正在寻找行t3那些在存在t1但不是在t2 ,尝试:

select  t3.Items 
from    table3 t3
where   exists
        (
        select  *
        from    table1 t1
        where   t1.Items = t3.items
        )
        and not exists
        (
        select  *
        from    table2 t2
        where   t2.Items = t3.items
        )

Another solution is except : 另一种方案是except

select *
from
(
    Select Items 
    From Table1
    except
    Select Items 
    From Table2
) as Table3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM