One hour without result ?

  • Hello,

    Am I wrong somewhere ?

    I have two similar databases and I just want to count records on them.

    select count(*) from database1.dbo.tablex a, database2.dbo.tablex b

    where a.aDate > '2009-01-01' or b.aDate > '2009-01-01'

    I have cancelled this request after one hour of execution without any result !!

    If I split the request in two parts with counts stored into variables, then summed, the result is nearly immediate.

    So, is my first request wrong ? Or is there an explanation about this behaviour ?

    Thanks.

    Gedeon

  • What you did was to calculate the CARTESIAN PRODUCT.

    SELECT SUM(Items)

    FROM (

    SELECT COUNT(*) AS Items FROM TableA WHERE Col1 > '20090101' UNION ALL

    SELECT COUNT(*) AS Items FROM TableB WHERE Col1 > '20090101'

    ) AS d


    N 56°04'39.16"
    E 12°55'05.25"

  • Oops ! Stupid mistake ! :crazy:

    With millions of records in each table, sure it lasts a very long time...

    Thanks.

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

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