How do I put an 'if clause' in an SQL string?

前端 未结 9 1401
误落风尘
误落风尘 2021-01-29 18:16

So here\'s what I want to do on my MySQL database.

I would like to do:

SELECT *
    FROM itemsOrdered
    WHERE purchaseOrder_ID = \'@purchaseOr         


        
9条回答
  •  无人共我
    2021-01-29 18:49

    If the table contains millions of records then the following query will work fast.

    UPDATE PO
    SET PO.purchaseOrder_status = 'COMPLETED'
    FROM purchaseOrder PO
    LEFT OUTER JOIN itemsOrdered IOD ON IOD.purchaseOrder_ID = PO.purchaseOrdered_ID and IOD.status = 'PENDING'
    WHERE IOD.purchaseOrder_ID IS NULL
    

提交回复
热议问题