为什么我的查询显示重复数据?

时间:2015-11-14 06:52:41

标签: sql sql-server sql-server-2008 tsql sql-server-2012

如何在查询中停止这种重复?

见我有2个表格,

  1. PersonalInfo
  2. 培训
  3. 现在只有1个人的个人记录,但是TrainingsCourses可以超过1个记录。

    但问题是,在TrainingsCourses中,personalInfo记录也会重复我不想要的内容。

    SP:

    SELECT PersonalInfo.pk_PersonalInfo_ID,
           PersonalInfo.PersonalInfoReligion,
           PersonalInfo.PersonalInfoPhoneResidence,
           PersonalInfo.PersonalInfoPhoneoffice,
           PersonalInfo.PersonalInfoNIC,
           PersonalInfo.PersonalInfoName,
           PersonalInfo.PersonalInfoMobile,
           PersonalInfo.PersonalInfoMaritalStatus,
           PersonalInfo.PersonalInfoGender,
           PersonalInfo.PersonalInfoFatherHusbandName,
           Convert(varchar, PersonalInfo.PersonalInfoEntryDateTime, 106),
           PersonalInfo.PersonalInfoEmailAddress,
           PersonalInfo.PersonalInfoDomicile,
           Convert(varchar,PersonalInfo.PersonalInfoDOB, 106) AS PersonalInfoDOB,
           PersonalInfo.PersonalInfoComputerLiterate,
           PersonalInfo.PersonalInfoAddress,
           PersonalInfo.fk_WebUsers_PersonalInfo_UserID,
           PersonalInfoEmployeePicture,
           Qualification.AcademicQualification,
           Qualification.pk_Qualification_QualificationID,
           Qualification.fk_PersonalInfo_Qualification_PID,
           Qualification.QualificationGrade,
           Qualification.QualificationInstituteAddress,
           Qualification.QualificationInstituteName,
           Qualification.QualificationMajorSubjects,
           Qualification.QualificationPassingYear,
           Qualification.fk_PersonalInfo_Qualification_PID,
           TrainingsCourses.pk_TrainingsCourses_ID,
           TrainingsCourses.fk_PersonalInfo_TrainingsCourses_PID,
           TrainingsCourses.TrainingsCoursesCountry,
           TrainingsCourses.TrainingsCoursesCourseTitle,
           Convert(varchar, TrainingsCourses.TrainingsCoursesFromDate, 106) AS TrainingsCoursesFromDate,
           TrainingsCourses.TrainingsCoursesInstituteAddress,
           TrainingsCourses.TrainingsCoursesInstituteName,
           Convert(varchar, TrainingsCourses.TrainingsCoursesToDate, 106) AS TrainingsCoursesToDate
    FROM PersonalInfo
    INNER JOIN Qualification ON Qualification.fk_PersonalInfo_Qualification_PID= PersonalInfo.pk_PersonalInfo_ID
    INNER JOIN TrainingsCourses ON TrainingsCourses.fk_PersonalInfo_TrainingsCourses_PID= PersonalInfo.pk_PersonalInfo_ID
    WHERE PersonalInfo.pk_PersonalInfo_ID= @pk_PersonalInfo_ID
    

0 个答案:

没有答案