Parse & Compare Data using Coldfusion & MySQL

前端 未结 3 1724
情书的邮戳
情书的邮戳 2020-12-12 04:25

First, I\'ll explain what I need to do, then how I think I can achieve it. My current plan seems very inefficient in theory, so my question is whether there is a b

3条回答
  •  借酒劲吻你
    2020-12-12 05:17

    For finding the changes, I'd look at joins based on the fields you want to match on. This can be slow, depending on the number of fields and whether or not they're indexed, but I'd still say it was faster than loops. Something along the lines of:

    SELECT product_id
    FROM Products
    WHERE product_id NOT IN (
        SELECT T.product_id
        FROM Products_Temp T
        INNER JOIN PRODUCTS P
        ON (
            P.field1 = T.field1
            AND P.field2 = T.field2
            ...
        )
    )
    

    For the missing products to find the non-matches:

    SELECT P.product_id
    FROM Products P
    LEFT OUTER JOIN Products_Temp T
    ON (P.field1 = T.field1
        AND P.field2 = T.field2
        ...)
    WHERE T.product_id IS NULL
    

提交回复
热议问题