开发者

SQL (Mysql) order problem

I have the following query:

SELECT a.field_eventid_key_value, a.field_showdate_value, b.nid , c.nid AS CNID 
    FROM content_type_vorfuehrung AS a 
    LEFT JOIN content_type_movies as b ON a.field_eventid_key_value = b.field_eventid_value 
    开发者_开发知识库LEFT JOIN content_type_sonderveranstaltung as c ON a.field_eventid_key_value = c.field_sonderveranstaltungid_value
    WHERE /* something */
    GROUP BY a.field_eventid_key_value, a.field_showdate_value, 
    ORDER BY a.field_showdate_value ASC,a.field_showtime_value ASC 

(where clause removed since it's irrelevant to the question)

This pulls data from 3 different tables and sorts it according to the "showdate" field in the first table. This is used in a PHP function that returns an array with the results.

Now there is a new requirement: The table "content_type_movies" in this query has a field that's supposed to be a boolean (actually it's an int with a value of either "0" oder "1"). This field is supposed to override the chronological ordering - that is, results where the field is "true" (or "1" respectively) should appear at the beginning of the result array (with the remaining entries ordered chronologically as before).

Is this at all possible with a single query ?

Thank you in advance for your time,

eike


You can use:

ORDER BY b.MyIntField DESC, 
    a.field_showdate_value,
    a.field_showtime_value 

where MyIntField is the field that is either 1 or 0 that you want to sort first.


ORDER BY a.content_type_movies DESC, /*then other fields*/ a.field_showdate_value ASC,a.field_showtime_value ASC

that should place all rows with content_type_movies=1 first then others.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜