使用left join时如何在查询结果中不包含id

aamkag61  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(352)

我试图用三个表中的数据填充我的listview stu_tblbasicinfo , stu_tblfam 以及 stu_tbleducbackground 他们都有相同的身份 TagID ```
Select A.TagID , A.Surname, A.Firstname, A.Middlename, A.Course, A.Year, B.ZipCode,
B.Province, B.Municipality, B.Barangay, A.ContactNo, A.EmailAddress, A.Birthdate,
A.Age, A.Birthplace, A.Religion, A.Gender, A.CivilStatus, A.Spouse, C.Mothersname,
C.M_occupation, C.M_Number, C.Fathersname, C.F_Occupation, C.F_Number,
C.GuardianName, C.G_Occupation, C.G_Number, D.Elementary, D.E_Years, D.JuniorHigh,
D.J_Years, Seniorhigh, D.S_Years
from stu_tblbasicinfo As A
left join stu_tblzipcode As B
on A.Barangay = B.Barangay
inner join stu_tblfam As C
ON A.TagID = C.TagID
inner join stu_tbleducbackground As D
ON A.TagID = D.TagID

我的代码工作,但问题是它显示3个tagid。
结果是这样的 `TagID(studentinfo table),Surname,Firstname,Middlename,TagID(familyBackground table),MName,FName,Gname,TagID(EducBackground table),Elementary,E_years,JuniorHigh,J_Years,SeniorHigh,S_Years` 如何以这种格式生成结果? `TagID,Surname,Firstname,Middlename,Mname,Fname,Gname,Elementary,E.Years,JuniorHigh,J_Years,SeniorHigh,S_Years` 
qxsslcnc

qxsslcnc1#

就这样:

Select 
    A.TagID , 
    A.Surname, 
    A.Firstname, 
    A.Middlename,
    C.Mothersname,
    C.Fathersname, 
    C.GuardianName, 
    D.Elementary, 
    D.E_Years, 
    D.JuniorHigh,
    D.J_Years, 
    D.Seniorhigh,
    D.S_Years 
        from stu_tblbasicinfo As A
        left join stu_tblzipcode As B
            on A.Barangay = B.Barangay
        inner join stu_tblfam As C
            ON A.TagID = C.TagID
        inner join stu_tbleducbackground As D
            ON A.TagID = D.TagID

相关问题