【发布时间】:2012-03-10 04:01:37
【问题描述】:
我有一个table A
itemid itemname itemgroup
1 item1 group1
2 item2 group1
3 item3 group1
还有一个table B
itemid itemname itemgroup invid
1 item1 group1 1
3 item3 group1 1
在我的例子中,table B 是table A 的子集,或者table A 是table B 的超集(它是一个已经盘点的项目表)。有没有办法从table A 中获取group1 的记录列表,而table B 中不存在?不确定是否有集合操作从不包含在子集中的超集中获取记录(互斥)?
目前我正在使用以下代表性查询。这是实现这一目标的正确方法吗?我目前在 SQL Server 中工作,但也希望得到有关 Oracle 和 MySQL 的答案。
SELECT itemid, itemname, itemgroup
FROM tableA
WHERE itemid NOT IN (SELECT itemid
FROM tableB
WHERE invid = parameter)
【问题讨论】:
-
@OMGPonies 已编辑问题。目前正在使用 SQL 服务器,但是否可以使用 Oracle 或 MySQL。
标签: sql