I use Postgresql 9.1. I have a table and I would like to get two things done in one query:
First: select one random sample row:
select * from table order by random() limit 1;
Second: count the number of rows the sample was selected from:
select count(1) from table;
Since a proper random() function has to know about all rows, I wonder if there is a way to get both results in one query.
I am guessing for something link:
select count(1), first.* from table order by random();
but i don't really know how to do it.
So I want a random row and the total number of rows.
Thanks for any ideas.
Steve