I have a php based portal where i am adding question and getting error like this : A Database Error Occurred Error Number: 1054 Unknown column 'tblquestion_category.question_category_id' in 'where clause' SELECT `question_category`.`question_category_id`, `question_category`.`category_title`, `parent_category`.`category_title` as parent_category_title FROM (`tbl_question_category` AS question_category) LEFT JOIN `tbl_question_category` AS parent_category ON `tblquestion_category`.`parent_category_id`=`parent_category`.`question_category_id` WHERE `tblquestion_category`.`question_category_id` = '3' Filename: /home/enkatech/public_html/refitsmart.com/register/models/admin/configuration_model.php Line Number: 524
Have you made sure that the column question_category_id exists in tblquestion_category? Perhaps you made a small typo?
Well then you pasted the wrong code I guess because towards the end you clearly have WHERE `tblquestion_category`.`question_category_id` = '3' Code (markup):
You're redeclaring names all over, and you have not declared tblquestion_category anywere - you HAVE declared question_category as an alias for tbl_question_category and parent_category as an alias for the same... Also, there shouldn't be backticks ` around table names, just column names (and strictly speaking they're not really needed around column names either, they're there to make sure that you, if you use restricted words for column names (just don't), then it will still work).
I haven't used this word tblquestion_category anywhere in the code even i checked it doesn't seems to be there.
According to the SQL you posted above, tblquestion_category seems to be a table in your database. The error you are seeing is saying that the column question_category_id does not exist in the table tblquestion_category. The error is related to your SQL query and is not in your php code. Also as @PoPSiCLe said, the statement is really messy and looks weird although it should work if the column exists.
If you tell us the name of your table(s) and the name of your columns, we could probably create a correct query for you, if you explain what it is you're trying to do - from the query it seems you're joining the same table to get... something. But the query is a bit confusing, so it's a bit hard to fathom what that "something" is.
This really looks like a case where formatting would have saved you a lot of headaches, since it looks like all that was really wrong was you forgot two underscores. tblquestion instead of tbl_question if the rest of your table names are to be believed. It REALLY gets clearer if you keep the SQL commands in caps and throw a few carriage returns in there... and strip out the 'quotes for nothing' since the odds of ANY of those names raising a namespace conflict are effectively zero. SELECT question_category.question_category_id, question_category.category_title, parent_category.category_title AS parent_category_title FROM tbl_question_category AS question_category LEFT JOIN tbl_question_category AS parent_category ON tblquestion_category.parent_category_id = parent_category.question_category_id WHERE tblquestion_category.question_category_id = 3 Code (markup): WAY clearer to read... and those two typos stand out far, far more than they do in the endless wordwrapping line. Which of course corrected would read: SELECT question_category.question_category_id, question_category.category_title, parent_category.category_title AS parent_category_title FROM tbl_question_category AS question_category LEFT JOIN tbl_question_category AS parent_category ON tbl_question_category.parent_category_id = parent_category.question_category_id WHERE tbl_question_category.question_category_id = 3 Code (markup):