Hi,
I have to join five tables in sql server using primary and foreign keys .I have joine all the tables
but problem was duplicate rows were repeating.Could any body help me to resolve this problem.
Thanks in advance.
Regards,
Raja.
Could you post the query and the table relationships? No one will be able to help you without that.
|||
| | | | |
| 1.Feature | | | |
| | | | |
| Column Name | Datatype | Size | Constraints |
| | | | |
| | | | |
1 | FeatureId | UniqueIdentifier | | not null, primary key |
2 | FeatureName | varchar | 255 | not null |
| | | | |
| 2.Products | | | |
| | | | |
| | | | |
1 | ProductId | UniqueIdentifier | | not null,primary key |
2 | ProductName | varchar | 255 | not null |
| | | | |
| 3.Feature_Product | | | |
| | | | |
| |
1 | FeaturId | UniqueIdentifier | | not null,foreign key Feature |
2 | ProductId | UniqueIdentifier | | not null,foreign key Products |
| | | | |
| 4.Customer | | | |
| | | | |
| | | | |
1 | CustomerId | UniqueIdentifier | | not null,primary key |
2 | CustomerName | varchar | 255 | not null |
3 | Emailid | varchar | 255 | not null |
4 | Mobile | varchar | 255 | |
5 | Fax | varchar | 255 | |
6 | Telephone | varchar | 255 | |
7 | Address | varchar | 500 | |
8 | TypeId | int | identity | foreign key customertype |
| | | | |
| | | | |
| 5.Customer_Product | | | |
| | | | |
| | | | |
1 | CustomerId | UniqueIdentifier | | not null,foreign key Customer |
2 | ProductId | UniqueIdentifier | | not null,foreign key Products |
| | | | |
| 6.License | | | |
| | | | |
| | | | |
1 | LicenseId | UniqueIdentifier | | not null,primary key |
2 | Type | varchar | 255 | not null |
3 | Release_date | datetime | | not null |
4 | License_Version | varchar | 255 | not null |
5 | StartDate | datetime | | |
6 | EndDate | datetime | | |
7 | HostId1 | varchar | 255 | |
8 | HostId2 | varchar | 255 | |
9 | HostId3 | varchar | 255 | |
10 | HostName1 | varchar | 255 | |
11 | HostName2 | varchar | 255 | |
12 | HostName3 | varchar | 255 | |
13 | IPAddress1 | varchar | 255 | |
14 | IPAddress2 | varchar | 255 | |
15 | IPAddress3 | varchar | 255 | |
16 | No_Licenses | int | | |
17 | CustomerId | UniqueIdentifier | | not null,foreign key Customer |
18 | MailTo | varchar | 255 | |
| | | | |
| 7.License_Product | | | |
| | | | |
| | | | |
1 | LicenseId | UniqueIdentifier | | not null,foreign key License |
2 | ProductId | UniqueIdentifier | | not null,foreign key Products |
| select ProductName,FeatureName,LicenseType, REPLACE(CONVERT(VARCHAR(11), ReleaseDate, 106), ' ', '-') AS [ReleaseDate],LicenseVersion,REPLACE(CONVERT(VARCHAR(11), StartDate, 106), ' ', '-') AS [StartDate],REPLACE(CONVERT(VARCHAR(11), EndDate, 106), ' ', '-') AS [EndDate],HostID1,HostID2,HostID3,HostName1,HostName2,HostName3,ipaddress1,IPAddress2,IPAddress3,No_Licenses,MailTo,CustomerName,EmailID,Mobile,Fax,Telephone,Address from products p,feature f,feature_product fp,license_product lp, Customer_product cp, license l,customers c where p.productid = fp.productid and f.featureid = fp.featureid and l.licenseid = lp.licenseid and c.customerid = l.customerid and p.productid = cp.productid and p.productid = lp.productid and c.customerid = cp.customerid | | | |
| Hi Prasanth, These are the tables and relationship for my task and I worked with that code but duplicate rows are generated could you help me from this iisue. ThankYou, Rajasekhar. | | | |
|||
| | | | |
| 1.Feature | | | |
| | | | |
| Column Name | Datatype | Size | Constraints |
| | | | |
| | | | |
1 | FeatureId | UniqueIdentifier | | not null, primary key |
2 | FeatureName | varchar | 255 | not null |
| | | | |
| 2.Products | | | |
| | | | |
| | | | |
1 | ProductId | UniqueIdentifier | | not null,primary key |
2 | ProductName | varchar | 255 | not null |
| | | | |
| 3.Feature_Product | | | |
| | | | |
| |
1 | FeaturId | UniqueIdentifier | | not null,foreign key Feature |
2 | ProductId | UniqueIdentifier | | not null,foreign key Products |
| | | | |
| 4.Customer | | | |
| | | | |
| | | | |
1 | CustomerId | UniqueIdentifier | | not null,primary key |
2 | CustomerName | varchar | 255 | not null |
3 | Emailid | varchar | 255 | not null |
4 | Mobile | varchar | 255 | |
5 | Fax | varchar | 255 | |
6 | Telephone | varchar | 255 | |
7 | Address | varchar | 500 | |
8 | TypeId | int | identity | foreign key customertype |
| | | | |
| | | | |
| 5.Customer_Product | | | |
| | | | |
| | | | |
1 | CustomerId | UniqueIdentifier | | not null,foreign key Customer |
2 | ProductId | UniqueIdentifier | | not null,foreign key Products |
| | | | |
| 6.License | | | |
| | | | |
| | | | |
1 | LicenseId | UniqueIdentifier | | not null,primary key |
2 | Type | varchar | 255 | not null |
3 | Release_date | datetime | | not null |
4 | License_Version | varchar | 255 | not null |
5 | StartDate | datetime | | |
6 | EndDate | datetime | | |
7 | HostId1 | varchar | 255 | |
8 | HostId2 | varchar | 255 | |
9 | HostId3 | varchar | 255 | |
10 | HostName1 | varchar | 255 | |
11 | HostName2 | varchar | 255 | |
12 | HostName3 | varchar | 255 | |
13 | IPAddress1 | varchar | 255 | |
14 | IPAddress2 | varchar | 255 | |
15 | IPAddress3 | varchar | 255 | |
16 | No_Licenses | int | | |
17 | CustomerId | UniqueIdentifier | | not null,foreign key Customer |
18 | MailTo | varchar | 255 | |
| | | | |
| 7.License_Product | | | |
| | | | |
| | | | |
1 | LicenseId | UniqueIdentifier | | not null,foreign key License |
2 | ProductId | UniqueIdentifier | | not null,foreign key Products |
| select ProductName,FeatureName,LicenseType, REPLACE(CONVERT(VARCHAR(11), ReleaseDate, 106), ' ', '-') AS [ReleaseDate],LicenseVersion,REPLACE(CONVERT(VARCHAR(11), StartDate, 106), ' ', '-') AS [StartDate],REPLACE(CONVERT(VARCHAR(11), EndDate, 106), ' ', '-') AS [EndDate],HostID1,HostID2,HostID3,HostName1,HostName2,HostName3,ipaddress1,IPAddress2,IPAddress3,No_Licenses,MailTo,CustomerName,EmailID,Mobile,Fax,Telephone,Address from products p,feature f,feature_product fp,license_product lp, Customer_product cp, license l,customers c where p.productid = fp.productid and f.featureid = fp.featureid and l.licenseid = lp.licenseid and c.customerid = l.customerid and p.productid = cp.productid and p.productid = lp.productid and c.customerid = cp.customerid | | | |
| Hi Prasanth, These are the tables and relationship for my task and I worked with that code but duplicate rows are generated could you help me from this iisue. ThankYou, Rajasekhar. | | | |
No comments:
Post a Comment