简体   繁体   中英

Unknown column in order clause

#1054 - Unknown column 'default_ps_products.manufacturer_id' in 'order clause'

为什么我在下面的语句中出现上述错误,它在语句中没有p情况下可以正常工作,而且我没有使用 order 子句?

SELECT * FROM `default_ps_products` p WHERE p.`manufacturer_id` = 2

To solve this use SELECT p.* FROM instead of SELECT * FROM .

The reason is that phpMyAdmin is adding an ORDER BY to your query for the first column in the results grid. Because of the alias, the code that does this fails.

This issue reproduces on phpMyAdmin 4.0.6. I don't know the status on the latest 4.2.5

Since you posted a partial query this wasn't obvious from the start, but your full query makes it clear;

SELECT *
FROM default_ps_products
WHERE manufacturer_id=2
ORDER BY `default_ps_products`.`manufacturer_id` ASC
LIMIT 0, 30

When you add an alias to default_ps_products table in the select, you can't selectively use the alias only in the WHERE clause, you'll also need to change the ORDER BY to use the same alias. The full query should in other words be;

SELECT *
FROM default_ps_products p
WHERE p.manufacturer_id=2
ORDER BY p.`manufacturer_id` ASC
LIMIT 0, 30

Open your phpmyadmin. Click on your selected database. Now you have a list of all tables on right side. Click on structure of default_ps_products table. Now you see a structure of it. Now Click on SQL tab and execute query as 'SELECT * FROM default_ps_products ORDER BY '. Once you execute this query, Now resolve your problem.

Your query is fine. there is not any error when i run this query. there is nothing wrong with query.

SELECT * FROM default_ps_products AS p WHERE p.manufacturer_id = 2 it working fine.:)

当使用@Query(nativeQuery = true) ,应该使用下划线格式,就像这样"Sort.by(Sort.Direction.DESC, "update_time")))" ,否则应该在实体中使用camel属性,就像这样"Sort.by(Sort.Direction.DESC, "updateTime")))"

phpmyadmin started showing this error suddenly on one table. only fix was to rename column id to id2 then back. even deleting the table and making new copy didn't help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM