Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
i have 3 tables for example tb1,tb2,tb3 and each table include same data for different different company, so i want to get all 3 table data in a view when i do "union" its sowing duplicate data also. the reason is, not having same data in each column for duplicate rows. like below, can any one please help me. i want only one row from below
Note: emp_no is primary key
ex:-

emp_no   emp_name   emp_addr     emp_ph
101      abcd       xloc         000000 -- from tbl1
101      abcd       null         000000 -- from tbl2
Posted
Updated 27-Nov-15 22:31pm
v2
Comments
Mehdi Gholam 28-Nov-15 4:20am    
You probably need another column for the "company name" of the tb1-3 tables otherwise stands to reason you will get duplicate data.

1 solution

Basically, you shouldn't have different tables for different companies - you have have one table which contains a foreign key link to a separate table which just identifies the companies:
Companies
Id      Description
1       Joes Wheels
2       Mikes Tyres
3       Simons Hubs

DataTable:
Id      CompanyId  EmpNo   EmpName   ...
1       1          101     abcd
2       3          101     abcd
3       1          102     qwer
...
That way, you can identify "genuine" duplicates, and extract only the info you need for each company using JOIN and WHERE instead of UNION

This also makes it a lot more flexible to add a fourth company next week if you need to.
 
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