difference in number of records for select count(*) and select *

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karpalmera
    New Member
    • Jun 2007
    • 14

    difference in number of records for select count(*) and select *

    We are trying to do select count(*) and select * from the same table.

    We have executed the following:
    when we execute
    Code:
    SELECT COUNT(*)
    FROM TABLE1;
    the result is 0
    but when we execute
    Code:
    SELECT *
    FROM TABLE1;
    the result is..
    Code:
    COLUMN1   COLUMN2
    1                 A
    2                 B
    two records selected.

    what could possibly cause this discrepancy?
    Last edited by eWish; Dec 30 '07, 03:50 PM. Reason: Added Code Tags
  • MindBender77
    New Member
    • Jul 2007
    • 233

    #2
    Hello,

    Select (*) - will count the total number of records in the table

    Select * - will list all records in the table

    Comment

    • docdiesel
      Recognized Expert Contributor
      • Aug 2007
      • 297

      #3
      Hi,
      Originally posted by MindBender77
      Select (*) - will count the total number of records in the table
      Select * - will list all records in the table
      Yes, correct. But the "SELECT count(*) should have given 2 as result, not 0 (zero), for there're two rows in the table. Try a
      Code:
      SELECT
        count(column1)
      FROM
        table1
      or another column. What's the result?

      Regards,

      Bernd

      Comment

      • karpalmera
        New Member
        • Jun 2007
        • 14

        #4
        We have REORG the table. This seems to solve the problem. The number of records for select * and select count(*) are now the same.

        But I still want to know the reason behind it.

        I'll try the select count per column if the problem arises again.

        I'll give an update regarding this..Super thanks!

        =============== =============== =============== ====



        Originally posted by docdiesel
        Hi,

        Yes, correct. But the "SELECT count(*) should have given 2 as result, not 0 (zero), for there're two rows in the table. Try a
        Code:
        SELECT
          count(column1)
        FROM
          table1
        or another column. What's the result?

        Regards,

        Bernd

        Comment

        Working...