sql server从两个表中选择colums不相等的表

时间:2016-03-13 00:12:01

标签: mysql sql-server

我对sql很新,所以请耐心等待。我有两个名为vascuproimagefiledatamig1.imagefile的表。我想将vascuproimagefile.imagefilevascuproimagefile.thumbnail<>进行比较,并返回select * from datamig1, vascuproimagefile where datamig1.ImageFile = vascuproimagefile.ImageFile; 彼此的结果。我能够运行这个查询,他们=彼此在哪里,它完美的工作原因为什么它不能用于&lt;&gt;

<!DOCTYPE html>
<html>
<head>
    <style>
    </style>
</head>
<body>
    <div class="onlyOne" data-need="hey there"></div>
    <script type="text/javascript">
        var myVar = document.getElementsByClassName("onlyOne")[0].getAttribute("data-need");
        alert(myVar);
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

有几种不同的方法可以做到这一点。一种是使用outer join / null支票:

select d.imagefile
from datamig1 d
   left join vascuproimagefile v on d.imagefile in (v.ImageFile, v.thumbnail)
where v.imagefile is null and v.thumbnail is null

或者您可以使用not exists

select imagefile
from datamig1 d
where not exists (
    select 1
    from vascuproimagefile v
    where d.imagefile = v.imagefile or d.imagefile = v.thumbnail 
)