CodePudding user response:
select name, case n the when then 0 else 1 end as upd from
(select name, sum (n) as n the from
(select name, 1 as n the from a_table
Union all
Select the name, 1 as n the from b_table) t
Group by name) t
CodePudding user response:
You say what should be displayed in A table in table B, said A new column 1, 0 means no? Use left actually join can solve
The select A.n ame, ISNULL (B1) FExists, 0)
From A left join (select name, 1 AS FExists from B) B1 ON A.n ame=B1. The name
CodePudding user response:
SELECT A.n ame,
CASE
The WHEN B.n ame IS NULL THEN 0
The ELSE 1
END the AS/update column
FROM A
LEFT the JOIN B
ON A.n ame=B.n ame