Simon Slavin <slav...@bigfraud.org> wrote: > I'm trying to write some code which has to be useful under many different > circumstances. Something I want to be able to do is to > take an arbitrary SELECT statement and replace the columns which would > normally be returned with COUNT(*) to find out how many > rows would be returned. To do this I replace the text between "SELECT" and > "FROM".
An alternative might be to wrap the counting SELECT around the original statement: select count(*) from ( select ... ); > I suspect this won't work well with unusual SELECTs which include sub-selects. I don't think subselects between SELECT and FROM should be any problem. Of course you'd need to count parentheses and quotes and square brackets carefully to find the right FROM. SQLite has a non-standard extension whereby aliases assigned to expressions in the SELECT clause may be used in the WHERE and other clauses: select 1+2 as alias from mytable where alias > 0; > I'm trying to get my head around whether JOINs could be a problem. I don't see how. > Also, does anyone know whether some combination of NULs might make COUNT(*) > give the wrong result ? No. COUNT(*) counts the number of rows, regardless of what those rows contain. -- Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users