Pattle
Pattle

Reputation: 6014

count(*) returning negative value

I have a strange problem and something that I haven't come across before. I have a mysql query like the one below

SELECT COUNT( * ) AS total_count FROM postcodes WHERE prefix='M1';

My query matches one row so I am expecting the value of total_count to be 1. However instead it is returning -1. Does anyone know why if would be returning a negative value?

Upvotes: 5

Views: 3217

Answers (2)

Timo
Timo

Reputation: 8690

Did you use ExecuteNonQuery instead of ExecuteScalar? Or in more general terms, did you read the row count instead of the result [in the first column of the first row]?

That's what I did to get a -1. Oops.

Upvotes: 0

ta.speot.is
ta.speot.is

Reputation: 27214

According to this bug report, you need to run REPAIR TABLE.

Upvotes: 4

Related Questions