Skip to content Skip to sidebar Skip to footer

Joining Two Table And Result Come Twice In Result

i have a select command in my query that fetch data from two table , and each row of result come twice in result , my query is Select Driver.DriverID, Driver.FName, Drive

Solution 1:

you need where condition if Driver and Contractor tables have relationship between them.

something like

Select  
  Driver.DriverID,
  Driver.FName,
  Driver.LName,
  Driver.SmartCardNumber,
  Driver.DriverState,
  Driver.DriverCity,
  Driver.DriverAddress,
  Driver.Mobile,
  Driver.Telephone,
  Driver.MelliCardNumber, 
  Driver.CertificatePublisher,
  Driver.addeddate,
  Driver.ContractorID,
  Driver.editeddate,
  Contractor.name  
From Driver,Contractor
    where Driver.ContractorID = Contractor.id

assuming ContractorID is linked to the id of Contractor.

Solution 2:

You can try use DISTINCT.

SELECTDISTINCT  Driver.DriverID,
Driver.FName,
Driver.LName,
Driver.SmartCardNumber,
Driver.DriverState,
Driver.DriverCity,
Driver.DriverAddress,
Driver.Mobile,
Driver.Telephone,
Driver.MelliCardNumber,
Driver.CertificatePublisher,
Driver.addeddate,
Driver.ContractorID,
Driver.editeddate,
Contractor.name  

From Driver,Contractor

Or if you don't need a CROSS result, then you can try to make a LEFT or INNER JOIN if you have a reference between the two table

Solution 3:

You need to tell the dbms how to join the records from the 2 tables:

For instance

Select 
  Driver.DriverID,
  Driver.FName,
  ...,
  Contractor.name  
  From Driver,Contractor
  Where Driver.ContractorID = Contractor.ID;

Or

Select 
  Driver.DriverID,
  Driver.FName,
  ...,
  Contractor.name  
  From Driver innerjoin Contractor
  On Driver.ContractorID = Contractor.ID;

Solution 4:

Select  Driver.DriverID,
Driver.FName,
Driver.LName,
Driver.SmartCardNumber,
Driver.DriverState,
Driver.DriverCity,
Driver.DriverAddress,
Driver.Mobile,
Driver.Telephone,
Driver.MelliCardNumber,
Driver.CertificatePublisher,
Driver.addeddate,
Driver.ContractorID,
Driver.editeddate,
Contractor.name  
From Driver,Contractor
where Driver.DriverId=Contractor.DriverId;

(mention some condition like this to fetch data)

Post a Comment for "Joining Two Table And Result Come Twice In Result"