+ Reply to Thread + Post New Thread
Results 1 to 3 of 3
  1. #1
    premamythili's Avatar
    premamythili is offline Junior Member
    Join Date
    24 Nov 2009
    Posts
    2
    Say Thanks
    0
    Thanked 0 Times in 0 Posts
    Documents
    0
    Uploads
    0

    Default what will be the return value of COUNT(*) if no records were selected by the group by

    Hi,
    i have a query like this
    select field1,count(*) from table1 where field1 in(5,3,7) group by field1

    i want zero to be displayed incase of no rows retrieved for the field1 values.

    field1 count(*)
    5 12
    3 15
    7 0

    can any of you plese help me on this?

    Thanks

  2.    Club-Oracle Complementary E-Books and Magazines
    Get your free Complementary Copy of Oracle Magazine

    You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.

  3. #2
    Sikkandar.S.P's Avatar
    Sikkandar.S.P is offline Junior Member
    Join Date
    16 Jan 2009
    Location
    Chennai
    Posts
    16
    Say Thanks
    0
    Thanked 0 Times in 0 Posts
    Documents
    0
    Uploads
    0

    Default Re: what will be the return value of COUNT(*) if no records were selected by the grou

    Code :

    SQL> SELECT FIELD1,COUNT(*) FROM TABLE1
      2  GROUP BY FIELD1
      3  ORDER BY 1
      4  /

        FIELD1   COUNT(*)
    ---------- ----------
             3         15
             5         12

    2 rows selected.

    SQL> SELECT   FIELD2,
      2           COUNT(FIELD1)
      3  FROM     TABLE1 A
      4           FULL OUTER JOIN (SELECT 3 FIELD2
      5                            FROM   DUAL
      6                            UNION ALL
      7                            SELECT 5
      8                            FROM   DUAL
      9                            UNION ALL
     10                            SELECT 7
     11                            FROM   DUAL) B
     12             ON A.FIELD1 = B.FIELD2
     13  GROUP BY FIELD2
     14  ORDER BY 1
     15  /

        FIELD2 COUNT(FIELD1)
    ---------- -------------
             3            15
             5            12
             7             0

    3 rows selected.
    Thanks,
    Sikki

  4. #3
    premamythili's Avatar
    premamythili is offline Junior Member
    Join Date
    24 Nov 2009
    Posts
    2
    Say Thanks
    0
    Thanked 0 Times in 0 Posts
    Documents
    0
    Uploads
    0

    Default Re: what will be the return value of COUNT(*) if no records were selected by the grou

    Thank u very much..

Similar Threads

  1. how to update Physical count in inventory module?
    By oraclelux in forum Oracle SCM
    Replies: 3
    Last Post: 01-18-2010, 10:47 AM
  2. Replies: 3
    Last Post: 10-13-2009, 07:04 PM
  3. Comparison of records in a table using cursors
    By lakshmi_9078 in forum SQL PL/SQL
    Replies: 2
    Last Post: 07-08-2009, 12:28 PM
  4. Replies: 4
    Last Post: 07-08-2009, 06:39 AM
  5. distinct count query
    By hiswapna in forum SQL PL/SQL
    Replies: 1
    Last Post: 05-05-2009, 05:44 AM

Tags for this Thread