This is a discussion on how to bring back the distinct values in single column from two tables within the SQL Server forums, part of the Microsoft SQL Server category; --> 12.) Now you have two different tables - each with two columns. Table #1 Single Column 2 rows with ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 12.) Now you have two different tables - each with two columns. Table #1 Single Column 2 rows with a value equal to 1 and 2 Table #2 Single column 2 rows with a value equal to 2 and 4 Construct a statement returning in a single column all the values contained, but not the common values. This is another question that I got in an interview, I missed it....... Thanks, Tim |
| ||||
| CREATE TABLE T1 (x INTEGER PRIMARY KEY) INSERT INTO T1 VALUES (1) INSERT INTO T1 VALUES (2) CREATE TABLE T2 (x INTEGER PRIMARY KEY) INSERT INTO T2 VALUES (2) INSERT INTO T2 VALUES (4) Method 1: SELECT COALESCE(T1.x, T2.x) FROM T1 FULL JOIN T2 ON T1.x = T2.x WHERE T1.x IS NULL OR T2.x IS NULL Method 2: SELECT x FROM (SELECT x FROM T1 UNION ALL SELECT x FROM T2) AS T GROUP BY x HAVING COUNT(*)=1 -- David Portas ------------ Please reply only to the newsgroup -- |