开发者

Update rows in table A NOT present in table B

开发者 https://www.devze.com 2023-01-09 16:30 出处:网络
I need to list (and later update) all the items present in the table art who are never referenced in the table orders_items

I need to list (and later update) all the items present in the table art who are never referenced in the table orders_items

table art

- artID - artName

Table orders_items

- itemID

- parentID

If i would be looking only by artID=itemID the query is pretty straightforward

select artID, itemID, artName, parentID
FROM art
LEFT JOIN orders_items ON artId=itemID
WHERE stock1=0 and stock3=0 AND itemID is nu开发者_如何转开发ll
GROUP BY artID;

But the problem is that I need to look in itemID AND parentID

Tryed with a subquery but it takes ages and i had to cancel it (art has 30000 records and orders_items near 200000)

In my mind I see an IN() and a GROUP_CONCAT() but I can't get this to work...


I like to keep this post from Jeff bookmarked. I'm not sure how it will perform, but it seems like you could do itemID=artID OR parentID=artID

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号