Hi,

I have an array with ID values. Let's say it looks like this - $a = array(23,4,56,21,9);
What i need is to select rows with those ID's, but in exact same order as in the array. What would be the best way to do that? If i use MySQL function IN(23,4,56,21,9) without specifying order, would that work?

Thanks

    SELECT *
    FROM tbl_test
    WHERE id
    IN ( 23,4,56,21,9)
    ORDER BY FIELD( id,23,4,56,21,9 )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.