Check if column value exists in another column in SQL

sql-server

Solution

This should work:

SELECT ID FROM [TableName]
WHERE Calling_ID IN
(
SELECT Called_ID FROM [TableName]
)

Problem

I need a SQL query that compares two values and returns an ID. I have this table: ``` ID Calling_ID Called_ID 1 27 10 2 15 20 3 80 90 4 90 88 5 60 30 6 88 40 7 15 60 8 30 40 9 27 95 10 40 30 ``` How do I check if each value in the `Calling_ID` column exists in the `Called_ID` column and then return the ID? The above data would return 88, 30, 40.

Original source