SQL

DECLARE @tableY TABLE (Number INT) DECLARE @tableX TABLE (Number INT) INSERT INTO @tableY SELECT 123456 UNION SELECT 345633 UNION SELECT 243234 UNION SELECT 865445 INSERT INTO @tableX SELECT 345633 UNION SELECT 243234 UNION SELECT 865445 SELECT Y.Number, CASE WHEN ISNULL(x.Number,'') = '' THEN 0 ELSE 1 END 'Exists' FROM @tableY y LEFT JOIN @tableX x ON y.Number = x.Number

Output:

Number Exists 123456 0 243234 1 345633 1 865445 1