#1054 - Unknown column 'default_ps_products.manufacturer_id' in 'order clause'
Why am I getting the above error with the statement below it works fine without the p
in the statement and I am not using an order clause?
SELECT * FROM `default_ps_products` p WHERE p.`manufacturer_id` = 2
By Tech-Assured. January 27, 2021 22496 Views. If you see this error, it means you have forgotten something while creating table.
To fix the 1054 error caused by an UPDATE statement, you need to look into the SET and WHERE clauses of your statement and make sure that the column names are all correct. You can look at the error message that MySQL gave you to identify where the error is happening.
The order of columns/expressions showing up does matter. It orders by the first one as specified, then orders that set by the next one, then by the next. The result is different than if you were to reverse the order in which the columns are ordered.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With