TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: Neil Heller
from: Darin McBride
date: 2003-02-01 18:47:34
subject: Counting with SQL

Hello Neil!

Replying to a message of Neil Heller to Daren McBride:

Who's "Daren" ?  :-)

 NH> Here's an interesting statement that I've found on several web sites,
 NH> as  well as my own ODBC documentation:

 NH> Note:  Many data sources cannot return the number of rows in a result 
 NH> set before fetching them; for maximum interoperability, applications 
 NH> should not rely on this behavior.

Very true.

 NH> I think I'm SOL.

No - you're trying to do a count(*), which is quite different.  If you were to do:

SELECT * FROM tbl WHERE ...

then what you read is true.  For this SELECT, you may or may not be able to
determine how many rows are being returned before actually reading them. 
However, if you do this:

SELECT COUNT(*) FROM tbl WHERE ...

This query returns A SINGLE ROW with A SINGLE VALUE.  You read it exactly
the same as any other SELECT that has a single row returned with a single
value - no need to loop through anything.

Darin
C_PLUSPLUS moderator
dmcbride{at}tower.to.org

---
* Origin: Tanktalus' Tower BBS (1:250/102)
SEEN-BY: 633/267 270
@PATH: 250/102 99 10/345 379/1 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.