May 5, 2016 at 6:16 pm
Hi,
I am a beginner in SQL and try to accomplish the select statement that only
return data when column in table1 have value not the same in table2
Table 1 Table 2
a 1
a 1
b 2
b 3
c 4
c 4
Result:
b 2
b 3
Please advise.
Thanks,
Dee
May 5, 2016 at 6:26 pm
post what you tried. Part of learning SQL is trying something, and failing, learning from your mistake, and trying again.
May 5, 2016 at 8:14 pm
Here's a fun solution that uses all three T-SQL set operators.
DECLARE @table1 TABLE (col1 char(3) unique);
DECLARE @table2 TABLE (col1 char(3) unique);
INSERT @table1 VALUES ('a 1'), ('b 2'), ('c 4');
INSERT @table2 VALUES ('a 1'), ('b 3'), ('c 4');
SELECT Col1 FROM @table1
UNION ALL
SELECT Col1 FROM @table2
EXCEPT
SELECT Col1 FROM @table1
INTERSECT
SELECT Col1 FROM @table2;
-- Itzik Ben-Gan 2001
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply