FooKelvin Posted August 19, 2016 Share Posted August 19, 2016 Hi Guys, i have a problem regarding on joining multiple tables, i was trying up for few days, but still can't get it done. This database is to join employee survey question regarding to one of the cafe. Below are my current non-working query. SELECT question.*, question_options.*, answer.*,txtanswer.* FROM question LEFT JOIN question_options ON question.question_id = question_options.question_id LEFT JOIN answer ON answer.option_id = question_options.qtn_option_id JOIN txtanswer ON txtanswer.qtn_option_id= question_options.qtn_option_id WHERE answer.empid = 'EMP8969' This query show no result when i join to the txtanswer table. Please download the attachment to view my table data. Thanks for your help. Jointable.zip Quote Link to comment https://forums.phpfreaks.com/topic/301939-join-multiple-table/ Share on other sites More sharing options...
Solution Barand Posted August 19, 2016 Solution Share Posted August 19, 2016 I'd make a couple of changes move the WHERE condition to the JOIN condition for the answer table use a LEFT join for the txtanswer table SELECT question.*, question_options.*, answer.*,txtanswer.* FROM question LEFT JOIN question_options ON question.question_id = question_options.question_id LEFT JOIN answer ON answer.option_id = question_options.qtn_option_id AND answer.empid = 'EMP8969' LEFT JOIN txtanswer ON txtanswer.qtn_option_id= question_options.qtn_option_id And don't use *s in the SELECT, specify the required fields. Quote Link to comment https://forums.phpfreaks.com/topic/301939-join-multiple-table/#findComment-1536332 Share on other sites More sharing options...
FooKelvin Posted August 22, 2016 Author Share Posted August 22, 2016 Thanks Barand! Quote Link to comment https://forums.phpfreaks.com/topic/301939-join-multiple-table/#findComment-1536437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.