in reply to Re^2: Sort AoH by another array
in thread Sort AoH by another array

The results have to be ordered in the order the user selected the items (using a web interface). I don't think there's a way to do that directly with an SQL ORDER BY clause.

I thought that too, and then I discovered this:

SELECT * FROM table ORDER BY FIELD( foo, 4, 2, 5, 1, 3 );

I'm not sure which versions of MySQL it works in, but definitely in 5.

Note there's a bug where you can't have a space between FIELD and the bracket.



Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...

Replies are listed 'Best First'.
Re^4: Sort AoH by another array
by saberworks (Curate) on Nov 06, 2007 at 17:39 UTC
    Hi, Thanks for your suggestion. Our application supports Oracle 9 & 10, and Postgres 8 (not MySQL). I will try that and see if it works, it will be a lot easier in this case.

    Update: it appears PostgreSQL doesn't support this.