Skip to content
Advertisement

compare data between two tables and populate a flag column in 1st table with ‘Y’if exist else ‘N”

I have two tables, if data exist in 1st table then populate flag column with ‘Y’ if does not populate with ‘N’, I am comparing only 3 columns, one is number, 2nd is name and 3rd column is datetime. However my busines rule case statment always returns ‘Y”

so last column 4 in table 2 should populate to y/n based if data is in table 1 or not. I have wrote query as like:

Advertisement

Answer

You’re checking if the three values individually exist in the other table, which is likely almost always the case. Looks like you need to check for the combined value, which would look something like the query below.

I took the libery of removing the with part, since that didn’t seem necessary here. But you could keep it as well, the solutions would be the same (apart from the table alias used).

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement