not inquery help

  • SELECT * FROM #temp1 WHERE ID NOT IN(SELECT ID FROM #temp3)

    I WANT all the IDS in #temp1 that are NOT IN #temp2

    BUe In am not getting the result with the above query.What should be the wrong with that.

  • Other than the typoe of using temp3 instead of temp2 (or vice versa ), I don't see anything wrong. Have you displayed the contents of both table to assure you have the expected values?

    Guarddata-

  • What are the data types? Is it possible that there is a some subtle mismatch?

  • Are there any NULL ID's in #temp3

    If so, you won't get any results.

    If this is the case, either add a clause AND ID IS NOT NULL when selecting from #temp3 or use WHERE NOT EXISTS (...#temp3)instead.

  • I have found that using a join normally produces a faster query.

    SELECT t1.*

    FROM #temp1 t1

    LEFT JOIN #temp2 t2

    ON t2.ID = t1.ID

    WHERE t2.ID IS NULL

    RandyHelpdesk: Perhaps Im not the only one that does not know what you are doing. 😉

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

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