Monday, March 12, 2012

Joining 5 tables

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 NameDatatypeSizeConstraints1FeatureIdUniqueIdentifiernot null, primary key2FeatureNamevarchar255not null 2.Products 1ProductIdUniqueIdentifiernot null,primary key2ProductNamevarchar255not null 3.Feature_Product 1FeaturIdUniqueIdentifiernot null,foreign key Feature2ProductIdUniqueIdentifiernot null,foreign key Products 4.Customer 1CustomerIdUniqueIdentifiernot null,primary key2CustomerNamevarchar255not null3Emailidvarchar255not null4Mobilevarchar2555Faxvarchar2556Telephonevarchar2557Addressvarchar5008TypeIdintidentityforeign key customertype 5.Customer_Product 1CustomerIdUniqueIdentifiernot null,foreign key Customer2ProductIdUniqueIdentifiernot null,foreign key Products 6.License 1LicenseIdUniqueIdentifiernot null,primary key2Typevarchar255not null3Release_datedatetimenot null4License_Versionvarchar255not null5StartDatedatetime6EndDatedatetime7HostId1varchar2558HostId2varchar2559HostId3varchar25510HostName1varchar25511HostName2varchar25512HostName3varchar25513IPAddress1varchar25514IPAddress2varchar25515IPAddress3varchar25516No_Licensesint17CustomerIdUniqueIdentifiernot null,foreign key Customer18MailTovarchar255 7.License_Product 1LicenseIdUniqueIdentifiernot null,foreign key License2ProductIdUniqueIdentifiernot 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 NameDatatypeSizeConstraints1FeatureIdUniqueIdentifiernot null, primary key2FeatureNamevarchar255not null 2.Products 1ProductIdUniqueIdentifiernot null,primary key2ProductNamevarchar255not null 3.Feature_Product 1FeaturIdUniqueIdentifiernot null,foreign key Feature2ProductIdUniqueIdentifiernot null,foreign key Products 4.Customer 1CustomerIdUniqueIdentifiernot null,primary key2CustomerNamevarchar255not null3Emailidvarchar255not null4Mobilevarchar2555Faxvarchar2556Telephonevarchar2557Addressvarchar5008TypeIdintidentityforeign key customertype 5.Customer_Product 1CustomerIdUniqueIdentifiernot null,foreign key Customer2ProductIdUniqueIdentifiernot null,foreign key Products 6.License 1LicenseIdUniqueIdentifiernot null,primary key2Typevarchar255not null3Release_datedatetimenot null4License_Versionvarchar255not null5StartDatedatetime6EndDatedatetime7HostId1varchar2558HostId2varchar2559HostId3varchar25510HostName1varchar25511HostName2varchar25512HostName3varchar25513IPAddress1varchar25514IPAddress2varchar25515IPAddress3varchar25516No_Licensesint17CustomerIdUniqueIdentifiernot null,foreign key Customer18MailTovarchar255 7.License_Product 1LicenseIdUniqueIdentifiernot null,foreign key License2ProductIdUniqueIdentifiernot 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