我有一个表“产品”和一个表“订单” Orders表包含以下字段:“id_products”和“id_users” 加入这两个表然后写:
SELECT * FROM products as p LEFT JOIN orders as o ON p.id_products=o.id_products
我想创建一个JOIN,其中包含您订购ID为1的用户的所有产品以及仍需订购的产品。
编辑:
SELECT * FROM products LEFT JOIN orders
ON products.id_products= orders.id_products
WHERE user_id = 1 OR user_id IS NULL
答案 0 :(得分:2)
SELECT * FROM products LEFT JOIN orders
ON products.id_products= orders.id_products
Where user.id = 1
答案 1 :(得分:0)
不
SELECT * FROM products as p LEFT OUTER JOIN orders as o ON p.id_products=o.id_products
where id_users = 1
做你想做的事吗?