Home > database >  In SQL how to compare two two columns of data values in the table are the same then take care about
In SQL how to compare two two columns of data values in the table are the same then take care about

Time:09-24

Details: A, B two tables have A 'name' column, values are equal in A matching table in table B, and will result in A material, according to A new column in the table about as shown in figure



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
  • Related