我想在MySQL中使用存储过程将3个表连接在一起并对其进行合并。
我已经检查了语法错误或名称错误的所有代码和参数,但找不到。
存储过程:GetOpenOrderFromUser()
DELIMITER $$
CREATE DEFINER=`present`@`%` PROCEDURE `GetOpenOrderFromUser`(IN `UserIDParam` INT)
READS SQL DATA
BEGIN
DECLARE OrderIDParam INT DEFAULT 0;
SELECT OrderID INTO OrderIDParam FROM _newapp_shop_orders WHERE UserID = UserIDParam AND Status = 'Open';
SELECT 'events' as Type,
Id,
Foto,
Video,
Titel,
Omschrijving,
Datum_Begin,
Datum_Eind,
Win,
Bovenaan,
Lat,
Lng,
_newapp_shop_order_items.OrderID,
_newapp_shop_order_items.Amount,
_newapp_shop_products_events.CategoryID,
_newapp_shop_products_events.Price,
_newapp_shop_products_events.DiscountPercent
FROM ((Events
INNER JOIN _newapp_shop_products_events ON Events.Id = _newapp_shop_products_events.EventID)
INNER JOIN _newapp_shop_order_items ON Events.Id = _newapp_shop_order_items.EventID)
WHERE _newapp_shop_order_items.OrderID = OrderIDParam
UNION ALL
SELECT 'activities' as Type,
Id,
Foto,
Video,
Naam as 'Titel',
Omschrijving,
Datum_begin,
Datum_eind,
Win,
Bovenaan,
Lat,
Lng,
_newapp_shop_order_items.OrderID,
_newapp_shop_order_items.Amount,
_newapp_shop_products_activitys.CategoryID,
_newapp_shop_products_activitys.Price,
_newapp_shop_products_activitys.DiscountPercent
FROM ((Activiteiten
INNER JOIN _newapp_shop_products_activitys ON Activiteiten.Id = _newapp_shop_products_activitys.ActivityID)
INNER JOIN _newapp_shop_order_items ON Activiteiten.Id = _newapp_shop_order_items.ActivityID)
WHERE _newapp_shop_order_items.OrderID = OrderIDParam;
END$$
DELIMITER ;
存储过程有时可以工作,当我从phpmyadmin运行它时,它可以工作,但是从代码和mysql终端中,它会出现此错误:
Expression missing. (near "ON" at position 25)
SET FOREIGN_KEY_CHECKS = ON;
#2014 - Commands out of sync; you can't run this command now.