Click here to Skip to main content
15,891,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have six tables in my SQL Server database.

Step 1: I UNION ALL Table 1, Table 2 and Table 3 into Datatable1.

Step 2: I UNION ALL Table 4, Table 5 and Table 6 into Datatable2.

In all the 6 tables the common columns are AlbumID,PictureID,StoryID.

Now I want to compare these columns in both the Datatables and put a flag (True) in Datatable1 where the data in both the datatables match else False.

I am thinking to use Linq or Lambda Expression to do the comparison. Is this the correct/best way to do this? OR should I go for TABLE JOINS?

Basically the table should have 4 columns :-

AlbumID, PictureID, StoryID, Flag
Flag would be true only if AlbumID or PictureID or StoryID is present in Datatable2
Posted

1 solution

I guess it's a matter of opinion, but personally I would either join the tables or use an EXISTS[^] clause.

However, the first thing I would do is to stop to think the database design itself. If you have tables that have so many common columns, it raises the question if the database s normalized properly.

So without knowing anything more about the tables, I would advice you to have a closer look at the database design and consider if instead of having 6 tables which all have columns AlbumID,PictureID,StoryID could you simplify the design.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900