web123456

Unknown column 'rownum' in 'where clause' solution

Unknown column 'rownum' in 'where clause', this problem will be encountered when using rownum in nested query statements, such as:

SELECT * FROM  (select , from USER_INFO t where =0 order by t.EMP_ID desc)  _queryForTop  where rownum <=10;

When querying this SQL statement, you will encounter the error Unknown column 'rownum' in 'where clause'.

After reading the official explanation of mysql, I found that in the nested query statement, when using where, the number of data may not be determined yet, and rownum has not yet been released. So an error will be reported. Brothers who have encountered this problem can only change your SQL statement.

The official link of mysql is as follows: /?id=38879

/doc/refman/4.1/en/

The original text is as follows:

Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined.