Mysql IN (list here) sorted by Ids in list

$Query = "SELECT c.*, p.id as promoID FROM cars c  LEFT OUTER JOIN promo p ON c.ID = p.ID WHERE c.ID IN $INCLUDED_ID";

$INCLUDED_ID = (45667, 78967, 89977, 67786, etc)
promo is promo table cars, and cars table is main cars table (all)

MySQL: How result from this query is Not sorted per car ID - as is now but, order by series in $INCLUDED_ID …?

You need to add an order by clause at the end of your current statement, e.g.

order by field(c.id,45667, 78967, 89977, 67786,...)

Please note c.id in IN is Not ordered

So repeat twice the parentheses content one in IN and another in ORDER BY…?

Order by must be at end of query?

Your reply is somehow confused
Needed field and (c.id
?

what happened when you tested it? ™

1 Like

I am little confused…

“field” is keyword?

c.id param what do in fixed IDs that are inside parentheses??

I found and this

TESTED ok…NOW WORKING Thanks a lot this I didn’t know about mysql

no, FIELD() is function

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.