Reputation: 500
I have two tables called TableX and TableY. Both are identical table with following columns
ID int
Sname varchar(256)
TableX has following data
TableY has following data
How do I write a SQL Server statement that show me all matching record that in TableX and TableY on the SName?
The results I want to see is
I want to match it only by SName.
thanks community Nick
Upvotes: 0
Views: 47
Reputation: 69494
SELECT SNAME FROM TABLEX
INTERSECT
SELECT SNAME FROM TABLEY
OR
SELECT X.SNAME
FROM TABLEX X INNER JOIN TABLEY Y
ON X.SNAME = Y.SNAME
OR
SELECT X.SNAME
FROM TABLEX X
WHERE EXISTS (SELECT 1
FROM TABLEY
WHERE SNAME = X.SNAME)
Upvotes: 2