Where Condition ?

  • How do you know it is quicker? Did you measure both queries on your data?

    What if you have ten times more data? Do you realize that your solution will not use any indexes?

    Regards

    Piotr

    ...and your only reply is slàinte mhath

  • I'd definately check the execution plan on that. It might be easy to write and maintain, but I suspect it's doing multiple table scans. That's going to hurt, a lot.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Humm...Ok.

    --

  • This sounds like a perfect case for using EXCEPT or INTERSECT. Example:

    -- Create the tables

    CREATE TABLE #temp (a int, b int, c int);

    CREATE TABLE #temp1 (a int, b int, c int);

    -- Add some data

    INSERT INTO #temp (a, b, c)

    SELECT 1, 1, 1

    UNION ALL SELECT 1, 2, 2

    UNION ALL SELECT 1, 2, 1

    INSERT INTO #temp1 (a, b, c)

    SELECT 1, 1, 1

    UNION ALL SELECT 1, 2, 2

    UNION ALL SELECT 1, 2, 3

    -- Find rows in #temp except matching rows in #temp1

    SELECT * FROM #temp

    EXCEPT SELECT * FROM #temp1;

    -- Find rows in #temp matching rows in #temp1

    SELECT * FROM #temp

    INTERSECT SELECT * FROM #temp1;

    DROP TABLE #temp;

    DROP TABLE #temp1;

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • As this is SQL Server 2005, how about this:

    select

    EmpID,

    EmpName,

    Pin

    from

    dbo.Table1

    except

    select

    EmpID,

    EmpName,

    Pin

    from

    dbo.Table2

    😎

Viewing 5 posts - 16 through 19 (of 19 total)

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