Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^3: Perl and MySQL: Get number of rows affected

by Samy_rio (Vicar)
on Jul 15, 2006 at 12:07 UTC ( #561430=note: print w/replies, xml ) Need Help??

in reply to Re^2: Perl and MySQL: Get number of rows affected
in thread Perl and MySQL: Get number of rows affected

In MySql documentation, I got the below query:

Query from documentation : SELECT COUNT(ip), AVG(down) from test;

When I run the below query, i am getting the following output.

Query which I ran: mysql> select count(us_name) from table where us_name='samy'; +----------------+ | count(us_name) | +----------------+ | 6 | +----------------+ 1 row in set (0.00 sec)

Velusamy R.

eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Replies are listed 'Best First'.
Re^4: Perl and MySQL: Get number of rows affected
by Ieronim (Friar) on Jul 15, 2006 at 13:23 UTC
    It seems that you don't know what the NULL values are :) Yes, in the case when the column value is declared as NOT NULL, COUNT(value) is equivalent to COUNT(*).

    But look at the example:

    CREATE TEMPORARY TABLE testnull0 ( id INT NOT NULL auto_increment, value VARCHAR(100), PRIMARY KEY(id) ) ENGINE=MyISAM; INSERT INTO testnull0 (id, value) VALUES (1, 'hello'), (2, 'googbye'), + (3, NULL); SELECT COUNT(id), COUNT(value), COUNT(*) FROM testnull0;
    Being processed by MySQL (you must specify your DB name, of course), it prints:
    +-----------+--------------+----------+ | COUNT(id) | COUNT(value) | COUNT(*) | +-----------+--------------+----------+ | 3 | 2 | 3 | +-----------+--------------+----------+
    Got the idea? You cannot rely on the suggestion that the value column is declared as NOT NULL, if you did not create the table yorself :) while COUNT(*) always works as expected.

    It's REALLY off-topic here, but i think that answering an OT question wrong is worse than answering it right—and even worse than not answering it at all.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://561430]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-08-14 13:47 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (150 votes). Check out past polls.