The situation:
- MySQL 5.0
- 2 tables
- 1-to-many parent-child foreign key relationship (A.ID = B.PARENT_ID)
What's needed:
- A SELECT query that yields the set of all the Nth children (sorted by their IDs)
- Also need a form for use in UPDATE
Example:
Table B
| ID | PARENT_ID |
------------------
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 2 |
| 6 | 2 |
| 7 | 2 |
| 8 | 3 |
| 9 | 3 |
| 10 | 4 |
Desired Result Set for, e.g., all 2nd children
| A.ID | B.ID | B.PARENT_ID |
-----------------------------
| 1 | 2 | 1 |
| 2 | 5 | 2 |
| 3 | 9 | 3 |
Perhaps something to do with a feature of GROUP BY that I am not seeing?
My mind has totally become stuck seeing the solution to this problem procedurally. All help much appreciated.