2

这不会显示结果

SELECT IMSLogin.AccountType, IMSLogin.Status, Registration.UsrFLname, Registration.UsrEmail, Employee.EMPID, Students.STUID, Employee.EMPDEPT, Franchise.FrArea, Franchise.FrName 
FROM Registration 
INNER JOIN IMSLogin ON Registration.RegId = IMSLogin.RegId 
INNER JOIN Employee ON Registration.RegId = Employee.RegId 
INNER JOIN Students ON Registration.RegId = Students.RegId 
INNER JOIN Franchise ON Registration.RegId = Franchise.RegId

但如果我在下面给出,将给出正确的结果

SELECT Registration.UsrFLname, Registration.UsrEmail, Students.STUID, Students.Pay_type, IMSLogin.AccountType, IMSLogin.Status 
FROM IMSLogin 
INNER JOIN Registration ON IMSLogin.RegId = Registration.RegId 
INNER JOIN Students ON Registration.RegId = Students.RegId

我的桌子:

Registration(RegId,PK) 
IMSLogin(RegId, FK) 
Students(RegId,FK) 
Franchise(RegId,FK) 
Employee(RegID,FK)

我试图在gridview中显示它,但我需要正确的查询,我不知道如何使用那个内部连接?

请帮忙....

谢谢...

4

2 回答 2

1

试试这个——

SELECT 
       l.AccountType
     , l.[Status]
     , r.UsrFLname
     , r.UsrEmail
     , e.EMPID
     , s.STUID
     , e.EMPDEPT
     , f.FrArea
     , f.FrName 
FROM dbo.Registration r
JOIN dbo.IMSLogin l ON r.RegId = l.RegId 
LEFT JOIN dbo.Students s ON r.RegId = s.RegId 
LEFT JOIN dbo.Employee e ON r.RegId = e.RegId 
LEFT JOIN dbo.Franchise f ON r.RegId = f.RegId
于 2013-06-27T05:24:53.860 回答
0

看来您的数据库设计很差。您应该有一个用户表,然后是有关学生、员工或特许经营权的任何细节的相关表。您的问题是,没有人可能同时在员工、学生和特许经营中。您很可能需要对所有这三个表进行左连接。

于 2013-06-26T19:29:17.900 回答