On Sun, 08 May 2011 11:09:36 -0400, Simon Slavin <[email protected]>
wrote:
>
> On 8 May 2011, at 4:00pm, Sam Carleton wrote:
>
>> How does one go about finding out how many rows a query returns?
>
> This was asked earlier this week. There is no magic way. Step through
> the rows and count them.
>
> You can, of course, do a preliminary SELECT for 'count(*)' and see what
> answer is returned.
How about:
SELECT count() FROM (<original query’s SELECT statement>);
Depending on the query, this might be possible and/or more obvious:
SELECT count()
FROM <original query’s join-source>
WHERE <original query’s WHERE clause>;
Quick test:
sqlite> CREATE TABLE "Test" ("col1" INTEGER, "col2" INTEGER);
sqlite> INSERT INTO "Test" VALUES (0, 1);
sqlite> INSERT INTO "Test" VALUES (1, 1);
sqlite> INSERT INTO "Test" VALUES (1, 2);
sqlite> SELECT count() FROM "Test" WHERE "col2" = 1;
2
sqlite> SELECT count() FROM "Test" WHERE "col2" = 2;
1
sqlite> SELECT count() FROM "Test" WHERE "col2" = 0;
0
sqlite> SELECT count() FROM
...> (SELECT "col1" FROM "Test" WHERE "col2" = 1);
2
sqlite> SELECT count() FROM
...> (SELECT "col1" FROM "Test" WHERE "col2" = 3);
0
That looks like a fairly “magic way” to me—and I have actually used that
method with nontrivial queries. Am I missing something? Too, I know how
an aggregate function is made; and I don’t see how this *wouldn’t* work
for an obvious implementation of a count() function.
Very truly,
SAMUEL ADAM ◊ http://certifound.com/ ◊ I read list mail sporadically.
763 Montgomery Road ◊ Hillsborough, NJ 08844-1304 ◊ United States
April 15, 2011 Courtroom Video in re Adam v. Supreme Court of N.J.:
http://www.youtube.com/watch?v=GPw2W2-Ujyc
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users