Mysql query to pick up certain rows froma table

Hello,

I have a table called priest and it has only two fields - priestid and priestname.

I want to pick up the rows where priestid=1, 5, 9, 13, 17,…till the end of the table

That means I want to pick up every 5th row (difference=4).

In know the statement :

select * from priest where priestid in (1,5,9)

But I want mysql to pick up on its own till the end of the table…I am stuck with this.

The following has not worked either:
$r=1;
$e=1;
while ($e<51)
{
$result = mysql_query(“SELECT * FROM priest where priestid limit $r,1”);
$r=$r+4;
}

Please help !!!


where mod(priestid,4) = 1

Of course with mysql_query now long dead and about to be removed from PHP you really ought to be using mysqli_query instead.

Thanks a lot… That worked.

One more query…if I leave the IDs and want to show the priest name of the first row, then priestname form the 5th row, then 9th and so on (irrespective of the IDs), how can it be done??

I have tried this with limit and offset but it did not work…

SELECT priestname
  FROM priest AS t
 WHERE MOD( ( SELECT COUNT(*)
                FROM priest
               WHERE priestid < t.priestid ),4) = 0