Mysql 从16个表中提取数据

Mysql 从16个表中提取数据,mysql,sql,Mysql,Sql,我有一个包含18个表的数据库,我需要从其中16个表中提取数据,我使用的查询不会产生任何错误,但我得到一个空集消息,所有表中都有数据,我使用的是连接的基本方法。有人能告诉我这是否可行,我是否可以用一个基本的查询来完成,或者我需要做一些联合或子查询 谢谢,伙计们 下面是一个查询 SELECT student.stuId, student.stuFName, student.stuLName, student.stuGender, student.stuMarSt, student.stuDOB, s

我有一个包含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中选择* 上的内部联接表2(tablea.id=tableb.id) 何处(条件)

如果效果良好,请添加另一个表

从表1中选择* 上的内部联接表2(table1.id=table2.id) 打开内部联接表3(下一个条件) 其中(条件)和(在此添加另一个条件)

如果效果良好,请添加另一个表

修复查询时,将*更改为要选择的特定字段集


这样,您将看到是否可以继续添加所有要加入的表。

检查加入条件。另外,在单个查询中连接16个表也不是一个好主意,因为可以使用16个(或更多)表生成查询,并且这样的查询可以生成数据。但是我们对您的表/数据一无所知,也许您可以提供您现在使用的查询。基本上,目前还没有更全面的答案来回答您不精确的问题。您能解释一下吗?还有其他方法来实现这一点吗?请注意,每当您枚举列名时,这肯定表明您的模式是非规范化的。您的教育表就是一个典型的例子。教育表所有枚举的字段都代表我们试图复制的表单中的字段,事实发生后,我也参与了这个项目,我遇到了一些问题,因为没有ERD,也没有进行适当的规范化。@DrewPierce-我也喜欢它+1感谢大家的帮助,特别是LU user1551066,我尝试了你的建议,找到了我的查询出了问题的地方。