SQL query

  • khwabekhan

    SSC Rookie

    Points: 31

    Comments posted to this topic are about the item SQL query

  • Hany Helmy

    SSChampion

    Points: 13321

    Interesting question, thanx Mohammad.

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • TomThomson

    SSC Guru

    Points: 104755

    accidental duplicate deleted

    Tom

  • TomThomson

    SSC Guru

    Points: 104755

    Stewart "Arturius" Campbell (3/7/2016)


    Nice one, thanks Mohammad.

    Yes, very nice.

    Read it as "how many rows retuned" first time round (pre-coffee).

    Me too!

    Fortunately reread it before clicking submit...

    I was less fortunate (because I was less careful :sick:) - and answered with the count (1) instead of the non-value (NULL). Stupid carelessness :blush :exclamation:

    Tom

  • Ed Wagner

    SSC Guru

    Points: 286955

  • George Vobr

    SSCrazy Eights

    Points: 8901

    Thanks for the interesting question Mohammad. Query result is better seen from this auxiliary script:

    DECLARE @emp TABLE ( id INT );

    INSERT INTO @emp VALUES ( 1 ),( 2 ),( NULL );

    SELECT id, COUNT(*) as Count_all,

    COUNT(id) as Count_id,

    COUNT(*) - COUNT(id) as All_minus_id_diff

    FROM @emp

    GROUP BY id

    HAVING

    COUNT(*) - COUNT(id) <> 0

    OR

    COUNT(*) - COUNT(id) = 0;

  • Y.B.

    SSChampion

    Points: 11357

    Almost got this one wrong, until I remembered COUNT(*) includes NULLs.

    Good reminder!


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • bgodick

    SSC-Addicted

    Points: 459

    Nice question. Thanks!

  • Revenant

    SSC-Forever

    Points: 42468

    yb751 (3/7/2016)


    Almost got this one wrong, until I remembered COUNT(*) includes NULLs.

    Good reminder!

    +1

    Thanks, Mohammad!

  • LoudClear

    SSC Eights!

    Points: 997

    "I prefer Count Star to Count Dracula, because I don't like having to consider which Draculas are NULL"

  • Bhushan Kulkarni

    SSCrazy

    Points: 2829

    Very Nice question. Thanks

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    Nice question, thanks.

  • Koen Verbeeck

    SSC Guru

    Points: 258890

    Interesting question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 15 posts - 1 through 15 (of 15 total)

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