Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Sort AoH by another array

by Cody Pendant (Prior)
on Nov 06, 2007 at 05:15 UTC ( [id://649150]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://649150]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-23 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found