Please help convert this 5.0 query to 4.0.27

Discussion in 'MySQL' started by 1-script.com, Sep 27, 2006.

  1. #1
    Hello eveyone!
    Banging my head against the wall trying to convert this into 4.0.27 - compatible format (no NOT EXISTS, no nestled SELECTs can be used) for a particular server I cannot upgrade.
    
            SELECT id AS del_id, parent AS del_parent, isanswer
            FROM `table1`
            WHERE isanswer = 1 AND NOT
            EXISTS (
            SELECT id
            FROM `table1`
            WHERE id = del_parent)
    
    Code (markup):
    It looks like LEFT JOIN would only help if I'm comparing two tables but I need to do this on a single table.

    Basically I can only think of a workaround that invloves a SELECT subquery which is not going to fly on pre-4.1 version 'cause you can only have INSERT ... SELECT and REPLACE ... SELECT subqueries.

    Please help!

    Cheers,

    D.
     
    1-script.com, Sep 27, 2006 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    SELECT
            a.id AS del_id,
            a.parent AS del_parent,
            a.isanswer
    FROM
            table1 a
    LEFT JOIN
            table1 b
    ON
            a.parent = b.id
    WHERE
            a.isanswer = 1
    AND
            b.id IS NULL
    Code (markup):
     
    SoKickIt, Sep 27, 2006 IP
  3. 1-script.com

    1-script.com Well-Known Member

    Messages:
    805
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    120
    #3
    SoKickIt,

    Sorry for the long delayed thank you :D

    I have not checked here for a while and in the meantime actually found the way to upgrade the mySQL instead. I am still doing some performance testing, so I'll use your query design to see if it performs better than the orignial one.

    Thanks again,

    D~
     
    1-script.com, Oct 14, 2006 IP