2015-08-05 3 views
-3

У меня есть база данных с 18 таблицами, и мне нужно вытащить данные из 16 из них, запрос, который я использовал, не генерирует никаких ошибок, но я получаю пустое сообщение, есть данные во всех таблицы, и я использую базовый метод соединений. может ли кто-нибудь предложить мне, если это будет возможно, и если я смогу выполнить это с помощью базового запроса или мне нужно сделать какой-то тип объединения или подзапроса?извлекать данные из 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 
+0

Проверьте условия участия. Также объединение 16 таблиц в одном запросе - не очень хорошая идея. IMO –

+0

Да, возможно генерировать запросы с использованием 16 (или более) таблиц и для таких запросов для создания данных. Но у нас нет нужных знаний о ваших таблицах/данных и, возможно, вы можете предоставить запрос, который используете сейчас. В принципе, прямо сейчас нет более полного ответа на ваш неточный вопрос. –

+0

Можете ли вы объяснить, и есть ли другой способ достичь этого? – bigaone22

ответ

3

Try присоединиться таблицу по одному.

выбрать * из table1 внутреннего соединения таблицы 2 на (tablea.id = tableb.id) где (условие)

, если это работает хорошо, чем добавить еще одну таблицу.

выберите * от table1 внутреннее соединение таблица2 на (table1.id = table2.id) внутреннее соединение (на Таблицу 3 следующему условию) где (условие) и (добавить еще одно условие здесь)

, если это работает а затем добавить другую таблицу

При исправлении вашего запроса измените * на определенные поля, которые вы хотите выбрать.

Таким образом вы увидите, можно ли продолжать добавлять все ваши таблицы, к которым вы хотите присоединиться.

+0

Мне нравится этот ответ – Drew

+0

@DrewPierce - Мне тоже понравилось +1 –

+0

Спасибо, как обычно, за помощь всем especiallu user1551066, я попробовал ваше предложение и смог найти, где мой запрос искал. – bigaone22

Смежные вопросы