'ERROR 1054 on the first ON when trying to JOIN a table column
SELECT od.order_header_id, product_name, order_qty, customer_name, oh.order_date, oh.total_price
FROM order_detail AS od
INNER JOIN order_header AS oh
ON (oh.total_price = od.total_price)
INNER JOIN order_header AS oh1
ON (oh1.order_date = od.order_date )
INNER JOIN product AS p
ON (p.product_name = od.product_name)
INNER JOIN customer AS c
ON (c.customer_name = od.customer_name )
WHERE oh1.order_date BETWEEN '2022-01-01' AND '2022-01-07'
GROUP BY od.order_header_id
ORDER BY od.order_header_id;
When I attempt to run this query it says there's an error at the first ON I receive error 1054 saying that there is no column named 'total_price' for the order_detail table.
The ERROR 1054 in MySQL occurs because MySQL can't find the column or field you specified in your statement.
*This query is to gather these different columns and display the data from 2022-01-01 to 2022-01-07 sorted by the order_header_id
Solution 1:[1]
SELECT order_detail.order_header_id, product.product_name, order_qty, customer.customer_name, order_header.order_date, order_header.total_price
FROM order_detail
INNER JOIN order_header
ON (order_header.order_header_id = order_detail.order_header_id)
INNER JOIN product
ON (product.product_id = order_detail.product_id)
INNER JOIN customer
ON (customer.customer_id = order_header.customer_id)
WHERE order_date BETWEEN '2022-01-01' AND '2022-01-07'
ORDER BY order_header_id;
I was using them incorrectly! lol
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CRoss |
