我有以下SQL(mysql):
SELECT SQL_CALC_FOUND_ROWS available.*
FROM available
WHERE `fname` LIKE '%de%'
ORDER BY `id` asc
我想将它与
结合起来LEFT JOIN cart ON available.id = cart.item_id
WHERE cart.item_id IS NULL
因此,结果只给出了不在购物车表格中的元素。
答案 0 :(得分:1)
您的查询应该是:
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
来自your comment:
没有“像fxx那样的fname”这没问题..但是有了它
答案 1 :(得分:0)
你把你的联接放在你之后,然后你的所有人都在那之后
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