Get different rows

  • hi

    is there a way to get all the rows from 2nd table that are not in 1st table .

    so for example there is a parent /child  table without the constraint , now we need all the rows in child which dont have a parent

    we can try

    select * from child where chilId not in (select parentId from parent)

    but is there a faster way of doin it for large dataset?

    thnks

    Amrita

  • You can also try

    select * from child c

    left join parent p on c.childID = p.parentID

    where p.parentID is null

    and see which is faster.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Check the not exists too compared to the left join.

  • And make sure you have good indexes, that will greatly improve join performance.

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply