Search code examples
mysqlmysql-error-1054

Error while executing the following mysql query


select name from movie as d
where d.mov = movie.mov;

. ERROR 1054 (42S22): Unknown column 'd.mov in 'where clause' . i sure that column mov exist.

but this is true

select name from movie as d
where d.mov = mov;

Solution

  • When you define an alias for a table you always have to use that alias.

    The first query does not work because once you have defined the alias, that table is now only accessible using that alias.

    The second query works because leaving out the table/alias prefix is legal as long as the column name is unique.