开发者

Can someone please help me with this sql query?

So at my job ive bee开发者_开发百科n asked to fix some sql code running on mysql 5 database and im stuck, also im not sure if this is the right place to do this but there is a small beer bounty on this question. Well send the top voted question some beer monies.

Basically the statement needs to do the following: Delete the row from customers_basket where products.products_quantity < 1 AND LOWER(inventory_t_product_minimum_stock.minimum_quantity) = 'nla'

This is the current statement:

DELETE FROM customers_basket 
WHERE EXISTS
    (SELECT products_id
        FROM inventory_t_product_minimum_stock
        WHERE customers_basket.products_id = 
            inventory_t_product_minimum_stock.products_id            
        AND LOWER(inventory_t_product_minimum_stock.minimum_quantity) = 'nla')

So really all that needs to change is add the bit about products_quantity < 1 however, that information comes from a different table.

Writing a simple left join for 3 tables wouldn't be difficult, my concern however is that this code is executed when the user logs in and joining three large tables would be a pretty big issue for us i imagine. Im actually a C developer come javascript coder some dbs are a little outside my area of expertise. Would one of the sql gurus out there have a good solution with out having to change our db schema?

edit* spelling


As long as your tables are properly indexed, and you're joining on the indexed fields, and your filters are targeting an indexed field, the query should perform fairly well.

Also, are you only deleting items in the customer basket table for the user logging in or for all products that have a quantity of < 1?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜