显示表1中的记录和表2中不存在的记录1
问题描述:
我有两个表,每个表中包含三个属性。我想要显示来自table 1
和table 2
的所有记录,只提取table 1
中不存在的记录。显示表1中的记录和表2中不存在的记录1
表1
ID Percentage OrderDate
+----+------------+----------+
1 2.0 2015-05-08
1 5.0 2014-05-08
1 19.65 2013-05-08
1 5.06 2012-05-08
1 98.0 2011-05-08
1 8.56 2010-05-08
+----+------------+----------+
表2
ID Percentage OrderDate
+----+------------+----------+
1 45.5 2015-05-08
1 45.23 2014-05-08
1 12.00 2013-05-08
1 6.45 2012-05-08
1 18.0 2011-05-08
1 5.2 2010-05-08
1 12.0 2009-05-08
1 22.78 2008-05-08
1 48.9 2007-05-08
1 7.89 2006-05-08
1 17.96 2005-05-08
1 11.3 2004-05-08
+----+------------+----------+
答
您可以使用EXCEPT
keyword:
SELECT ID, Pourcentage, OrderDate
FROM table1
UNION
(
SELECT ID, Pourcentage, OrderDate
FROM table2
EXCEPT
SELECT ID, Pourcentage, OrderDate
FROM table1
)
答
根据其列,您将可以比较你可以使用类似下面。
SELECT t1.ID, t1.Percentage, t1.OrderDate
FROM table1 t1
UNION ALL
SELECT t2.ID, t2.Percentage, t2.OrderDate
FROM table1 t1
INNER JOIN table2 t2 ON t2.ID <> t1.ID AND t2.Percentage <> t1.Percentage AND t2.OrderDate <> t1.OrderDate
答
,如果你想,如果你希望所有从表都使用工会的行删除重复利用工会
select ID, Percentage, OrderDate
from table1
union
select ID, Percentage, OrderDate
from table2
所有
select ID, Percentage, OrderDate
from table1
union all
select ID, Percentage, OrderDate
from table2
显示查询你已经试过吗?此外,他们被称为列。 –
不要忘记总是接受一个答案,帮助更多的人! –
完美我会这样做,但有时我真的忘记 – Ilyas