访问查询比较两个表

时间:2017-01-03 17:26:07

标签: sql ms-access nested-queries

我在Access,表A和表B中有两个表:

表MasterLockInsNew:

+----+-------+----------+
| ID | Value |   Date   |
+----+-------+----------+
|  1 |   123 | 12/02/13 |
|  2 |  1231 | 11/02/13 |
|  4 |  1265 | 16/02/13 |
+----+-------+----------+

表InitialPolData:

+----+-------+----------+---+
| ID | Value |   Date   |Type
+----+-------+----------+---+
|  1 |   123 | 12/02/13 | x |
|  2 |  1231 | 11/02/13 | x |      
|  3 |  1238 | 10/02/13 | y |      
|  4 |  1265 | 16/02/13 | a |      
|  7 |  7649 | 18/02/13 | z |      
+----+-------+----------+---+

我想要的只是来自表B的,用于未包含在A中的ID。我当前的代码如下所示:

SELECT Distinct InitialPolData.*
FROM InitialPolData
WHERE InitialPolData.ID NOT IN (SELECT Distinct InitialPolData.ID
                                from InitialPolData INNER JOIN
                                     MasterLockInsNew
                                     ON InitialPolData.ID=MasterLockInsNew.ID);

但是无论何时我在Access中运行它都会崩溃!!表格相当大,但我不认为这就是原因。

有人可以帮忙吗?

由于

3 个答案:

答案 0 :(得分:2)

简单的子查询可以。

select * from InitialPolData 
where id not in (
    select id from MasterLockInsNew
);

答案 1 :(得分:2)

或尝试 _treeChanged: function() { console.log(this.localName + '#' + this.id + ' tree data has changed'); // Assigns parent, children, height, depth var aa = this.$.polymerTree.getBoundingClientRect(); var svg_height = aa.height - 20 - 30; var svg_width = aa.width - 90 - 90; this.root = d3.hierarchy(this.tree, function(d) { return d.children; }); this.root.x0 = svg_height / 2; this.root.y0 = 0; if (g) { g.remove(); } zoomListener = d3.zoom() .scaleExtent([.5, 10]) .on("zoom", function () { g.attr("transform", d3.event.transform); } ); g = d3.select(this.$.polymerTree) .call(zoomListener) .on("dblclick.zoom", null) .append("g"); if (this.treemap) { this.update(this.root); this.centerNode(this.root); } },

left outer join

答案 2 :(得分:1)

尝试使用NOT EXISTS

SELECT Distinct i.* 
FROM InitialPolData AS i
WHERE NOT EXISTS (SELECT 1
                  FROM MasterLockInsNew AS m 
                  WHERE m.ID = i.ID)