-1

Could you please help me understanding why I am getting this error down below?

select business_questionnaire_id as question_id 
from lead_business_questionnaire 
where question_id = 5;

Error code: #1054 - Unknown column 'question_id' in 'where clause'

Ergest Basha
  • 4,865
  • 4
  • 5
  • 26
Timirey
  • 1
  • 1
  • 4
    The `WHERE` clause cannot use the alias of your column. You can use `WHERE business_questionnaire_id = 5` instead. – EdmCoff May 18 '22 at 14:54
  • in where clause you should use original column name. i.e business_questionnaire_id – Muhammad Abdullah May 18 '22 at 14:54
  • ??Why would you want to use the alias in the where clause. Consider the order of execution - in this case you are selecting.. from where..then aliasing. The where cannot know about the alias. – P.Salmon May 18 '22 at 14:54
  • The WHERE clause is evaluated _before_ the SELECT clause. I.e. question_id hasn't yet been defined. – jarlh May 18 '22 at 15:28

0 Answers0