I have two databases that I’m trying to transfer data between.
I’m working on getting orders from one to the other right now but I’ve run into something that I can’t figure out the correct way to do it.
Here’s the query thus far…
INSERT INTO `NEWTEST`.`Order_LineDetails`
( OrderLineItem_ID, Customer_ID, Order_ID )
SELECT
OrderDetailID,
(
SELECT o.CustomerID
FROM `OLDTEST`.`Order_Details` od
JOIN `OLDTEST`.`Orders` o ON o.OrderID = od.OrderID
),
OrderID
FROM `OLDTEST`.`Order_Details`
This is returning an error of ‘#1242 – Subquery returns more than 1 row’.
The result I’m going for would be to get…
OLDTEST.Order_Details -> NEWTEST.Order_LineDetails
OLDTEST.Order.CustomerID -> NEWTEST.Customer_ID
OLDTEST.Order_Details.OrderID -> NEWTEST.Order_ID
What am I missing?
:::::: EDIT :::::::
This is now correct and works fine.
SELECT
od.OrderDetailID,
o.CustomerID,
od.OrderID
FROM `OrderProcessing`.`Order_Details` od
JOIN `OrderProcessing`.`Orders` o ON o.OrderID = od.OrderID
LIMIT 100
When you use a subquery in the
SELECTclause as you did, it must return a single row, hence the error you’re getting.Actually you don’t seem to need the subquery here:
(Before running that, comment out the
INSERTline to make sure it’s giving the results you expect).