[英]left join including where on main table
I have the following SQL (mysql): 我有以下SQL(mysql):
SELECT SQL_CALC_FOUND_ROWS available.*
FROM available
WHERE `fname` LIKE '%de%'
ORDER BY `id` asc
I want to combine it with 我想将其与
LEFT JOIN cart ON available.id = cart.item_id
WHERE cart.item_id IS NULL
So that the result gives me only elements which are NOT in the cart table. 因此,结果只给我提供了不在购物车表格中的元素。
Your query should be: 您的查询应为:
SELECT SQL_CALC_FOUND_ROWS available.*
FROM available
LEFT JOIN cart
ON available.id = cart.item_id
WHERE cart.item_id IS NULL
AND `fname` LIKE '%de%'
ORDER BY `id` asc
From your comment : 根据您的评论 :
without the "where fname like xxx" it's no problem.. but with it
没有“像xxx一样的fname”,这没问题..但是有了它
Look at Multiple WHERE
conditions 查看多个
WHERE
条件
You put your joins after your from, and then all your wheres together after that 您将联接放在自己的位置,然后将所有位置组合在一起
SELECT SQL_CALC_FOUND_ROWS available.*
FROM available
LEFT JOIN cart ON available.id = cart.item_id
WHERE `fname` LIKE '%de%' AND cart.item_id IS NULL
ORDER BY `id` asc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.