rabesh Posted September 5, 2011 Share Posted September 5, 2011 I have used three tables tbl_question,tbl_answer,tbl_rating i need all data of three tables fileds of tbl_question are question_id question description user_id category_id question_slug date fields of tbl_answers are answer_id question_id user_id answer date fields of tbl_rating are rating_id answer_id point for the display of one questions and answers of related question by checking from question_slug field i used this query but not correct plz help $query= $this->db->query("(SELECT a.*,b.* FROM tbl_questions as a, tbl_answers as b where a.question_id=b.question_id AND a.question_slug='".$question_slug."') as c INNER JOIN (SELECT AVG(point) FROM tbl_rating)as c ON d.answer_id=c.answer_id ORDER BY d.answer_id DESC ")->result_array(); following error occurs A Database Error Occurred Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as c INNER JOIN (SELECT AVG(point) FROM tbl_rating)as c ON d.answer_id=c.answer_' at line 1 (SELECT a.*,b.* FROM tbl_questions as a, tbl_answers as b where a.question_id=b.question_id AND a.question_slug='Which-framework-is-mostly-Used-for-Php-Programming') as c INNER JOIN (SELECT AVG(point) FROM tbl_rating)as c ON d.answer_id=c.answer_id ORDER BY d.answer_id DESC Quote Link to comment Share on other sites More sharing options...
fenway Posted September 5, 2011 Share Posted September 5, 2011 What are you trying to do? Quote Link to comment Share on other sites More sharing options...
rabesh Posted September 6, 2011 Author Share Posted September 6, 2011 I am tryting to get all data of three table by evalutating question_slug with posted slug tbl_questions Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 6, 2011 Share Posted September 6, 2011 learn how to join, and maybe learn how to write SQL while you're at it: your error message relates to the fact that you have wraped the first section of the select within parenthesis and so terminate the select prematurely, not that it would work if you removed the parenthesis either. Really, that query is a mess...It should look something more like: SELECT tbl_question.question_id, question, description, user_id, category_id, question_slug, tbl_question.date AS q_date, tbl_answer.answer_id, user_id, answer, tbl_answer.date AS a_date, rating_id, point FROM tbl_rating LEFT JOIN tbl_answers ON (tbl_rating.answer_id = tbl_answers.answer_id) LEFT JOIN tbl_question ON (tbl_question.question_id = tbl_answer.question_id) WHERE tbl_question.question_slug = "$question_slug" ORDER BY tbl_answers.answer_id Quote Link to comment 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.