Php tutorials

Select every n-th row in mysql table like even or odd.

Google+ Pinterest LinkedIn Tumblr

We have faced some problem that we mysql table pulling entire table but we need a particular nth row order. Suppose we have lot of row in the table like 1000 rows but we need nth order row only, In this case, here is the code how to select every n-th row,  you can get particular n order

Demo                            Download

n_th order like

Step 1:  Consider the same table in previous post

nth_order show in mysql

Step 2 : very simple method

Here showing the nth order in even and odd id, that’s it very simple

nth_order show in mysql in even

or Another method for sorting nth order is

Set @row as 1 and add with rownum the div with your nth order

Enjoy code

I'm Rajasekar - Web developer, Freelancer, Blogger and Owner of DeveloperDesks. From India lives in Bahrain. I love to do coding, Creating websites and trying different with code and designs. You Can Hire Me