我有一个数据库查询
$extras = DB::select(
'SELECT p.*
FROM products p
WHERE required_product IS NULL
UNION ALL
SELECT p.*
FROM products p, orders o
WHERE p.required_product = o.product_id
AND o.user_id =' . $user->id . 'UNION ALL
SELECT p.* , "onlyOnce" product_type
FROM products p, orders o, only_once on
WHERE p.required_product = o.product_id
AND p.id = on.product_id
AND p.id NOT IN (SELECT product_id FROM orders WHERE o.product_id = p.id and o.user_id ='.$user->id.')'
);
以下是我的表格结构:
产品表:http://prntscr.com/k6jdv7
订单表: product_id,user_id
用户表: id,name,last_server,timestamps
1条答案
按热度按时间0tdrvxhp1#
语法错误。
试试这个。。。