I have some experience with MySQL, but I'm bogged down with this
problem. How do I select an arbitrary number of consecutive rows from
the current row?
Here's an example. Suppose I have a table with 2 columns and 8 rows like this:
------------
id | value
------------
1 | abc
2 | xmen
8 | irs
14 | fbi
17 | cia
22 | pda
40 | pdf
55 | six
Now, suppose I want to traverse the ID column, and select the VALUES
for the current ID and the next 4 IDs as well and CONCAT the values.
So the result would look like this:
------------
results
------------
abcxmenirsfbi /* id = 1 */
xmenirsfbicia /* id = 2 */
irsfbiciapda /* id = 8 */
fbiciapdapdf /* id = 14 */
ciapdapdfsix /* id = 17, last ID with 4 values concatenated */
pdapdfsix /* id = 22 */
pdfsix /* id = 40 */
six /* id = 55 */
I know I can load the results into an array in PHP and do it from
there, but my table has over 100,000 values and that defeats the point
of having a database.
Is there any way to do this? |