从16个表中提取数据

时间:2015-08-05 03:49:15

标签: mysql sql

我有一个包含18个表的数据库,我需要从其中的16个表中提取数据,我使用的查询不会生成任何错误,但我得到一个空集消息,所有表中都有数据,并且我使用的是连接的基本方法。任何人都可以建议我,如果这是可能的,如果我可以用一个基本的查询来完成这个或我需要做一些类型的联合或子查询?

感谢队友

以下是查询

SELECT student.stuId, student.stuFName, student.stuLName,
student.stuGender, student.stuMarSt, student.stuDOB,
student.stuAge, student.stuAddress, student.stuTown,
student.stuCountry, student.stuNation, student.stuEmail, 
student.stuPhone, student.stuAccType, student.stuAccNo, 
student.stuNISNo, student.stuBIRNo, student.stuBCPIN, 
student.stuPPNO, student.stuIDNO, student.stuDPNO, 
student.stuDA, student.verified, student.eduId, 
student.bankId, student.contId, student.courseId, 
student.courseId2, student.centreId, student.registrationDate,
bank.bankId, bank.bankName, bank.bankAddress, centre.centreId, 
centre.centreName, personalother.contId, personalother.contNameFname,
personalother.contNameLname, personalother.contStAddress,
personalother.contCity, personalother.contCountry, 
personalother.contTel, personalother.contRel, personalother.famBgndCh, 
personalother.famBgndChNo, personalother.famHhldNo,personalother.famHhldInc, 
personalother.genInfoPart, personalother.wrkExpJH1, personalother.wrkExpJH2,
rsonalother.wrkExpLJ,personalother.wrkExpPJName,personalother.wrkExpPJPhone,
personalother.wrkExpJNo, education.eduId, education.eduSchAtt,
education.eduExamBody1, education.eduExamLevel1, education.eduExamSubj1,
education.eduExamGrade1, education.eduExamBody2, education.eduExamLevel2,
education.eduExamSubj2, education.eduExamGrade2, education.eduExamBody3, 
education.eduExamLevel3, education.eduExamSubj3, education.eduExamGrade3, 
education.eduExamBody4, education.eduExamLevel4, education.eduExamSubj4, 
education.eduExamGrade4, education.eduExamBody5, education.eduExamLevel5, 
education.eduExamSubj5, education.eduExamGrade5, education.eduExamBody6,
education.eduExamLevel6, education.eduExamSubj6, education.eduExamGrade6,
education.eduExamBody7, education.eduExamLevel7, education.eduExamSubj7,
education.eduExamGrade7, education.eduExamBody8, education.eduExamLevel8,
education.eduExamSubj8, education.eduExamGrade8, geninfo.genInfoId, 
geninfo.genInfoName, stugeninfo.genInfoId, stugeninfo.stuId, 
stumarketing.mktgId, stumarketing.stuId, stuschatt.schAttId,
stuschatt.stuId, stuwrkexp.wrkExpId, stuwrkexp.stuId, stuwrkpay.wrkPayId,
stuwrkpay.stuId, school.schAttId, school.schAttName, bank.bankId,
student.verified, bank.bankId, courses.courseId, courses.occArea,
courses.courseName, courses.courseType, courses.courseLevel
FROM student, bank, centre, personalother, education, geninfo, 
stugeninfo, stumarketing, stuschatt, stuwrkexp, stuwrkpay,
school, courses,wrkexp,marketing
WHERE bank.bankid=student.bankId 
and education.eduid=student.eduid 
and personalother.contid=student.contid 
and centre.centreid=student.centreid 
and courses.courseid=student.courseid 
and student.stuid=stugeninfo.stuid 
and student.stuid=stuwrkpay.stuid 
and student.stuid=stuwrkexp.stuid 
and student.stuid=stumarketing.stuid 
and student.stuid=stuschatt.stuid 
and wrkexp.wrkexpid=stuwrkexp.wrkexpid
and marketing.mktgid=stumarketing.mktgid
and geninfo.geninfoid=stugeninfo.geninfoid 
and student.verified=0

1 个答案:

答案 0 :(得分:3)

尝试逐个加入表格。

从table1中选择* 内联接表2(tablea.id = tableb.id) 其中(条件)

如果这比添加另一个表更好。

从table1中选择* 内联接table2(table1.id = table2.id) 内连接table3 on(下一个条件) where(condition)和(在这里添加另一个条件)

如果这比添加另一个表

更好

修复查询后,将*更改为您要选择的特定字段。

通过这种方式,您将看到是否可以继续添加要加入的所有表格。