Hence, we can write a query directly against the table. However, opening the table in Grid View shows that orderNumber values are clearly sorted in ascending order:
We can see that its PK (the orderNumber column) is not auto-incrementing, as evidenced by the unchecked 'Auto Increment' checkbox: Otherwise, you may need to write a subquery with an ORDER BY clause and then select from it.Īs an example, let's open the orders table of the classicmodels sample database in Navicat Premium 16's Table Designer. Hence, auto-increment columns like those of a primary key make perfect candidates.
Ideally, its data should be numeric, unique, and sorted in ascending order. Picking a Suitable Target Columnīefore we can speak of 'even or odd rows' we have to order the rows by the column whose data we're interested in splitting. As a reader of this blog, you can save yourself the trouble of scouring database forums for a solution, as we'll set the record straight right here today. A quick Google search confirms that it's something that is done often enough, but, with few database practitioners knowing how, they invariably turn to online database communities in search of answers. Having to select only odd or even rows from a table sounds like something that you'd never have to do, that is until you do. Selecting Odd or Even Numbered Rows From a Table by Robert Gravelle