Home > Back-end >  Unknown column 'ename' in 'field list'
Unknown column 'ename' in 'field list'

Time:12-07

I don't understand how to fix this. PhpMyAdmin cannot find columns. I even gave each query a name but it doesn't work.

SELECT ename, 
       deptno FROM ( SELECT sal 
                     FROM emp T
                   ) as E 
WHERE deptno = 10;

CodePudding user response:

SELECT sal FROM emp T, return a table with only "sal" column. You select column ename and deptno from a table have only sal column is impossible.

CodePudding user response:

you have not a column named ename in the subquery that you are use as table

could be you don't need the subquery

SELECT ename, deptno 
FROM emp WHERE deptno = 10;

or if you really need the subquery then this must contain the column you are looking for

SELECT ename, deptno 
FROM (SELECT ename, deptno, sal FROM emp T) as E WHERE T.deptno = 10;

CodePudding user response:

Your sql is wrong, you are trying to select ename and deptno columns from table E. E alias from (SELECT sal FROM emp T), so it has the only one field named sal.

  • Related