join - mysql error table cannot be used in global order clause -


(select dtable.* app_detailsvvv dtable inner join new_apps on  new_apps.trackid=dtable.trackid primarygenrename='games' , composed='1' , new_apps.top>0) union (select * app_detailsvvv dtable primarygenrename='games') order new_apps.top asc, trackname asc limit 12 

with query error:

#1250 - table 'new_apps' 1 of selects cannot used in global order clause 

new_apps not used in second query, idea first top rank same table has listed id in new_apps table

as docs says

this kind of order cannot use column references include table name (that is, names in tbl_name.col_name format). instead, provide column alias in first select statement , refer alias in order by.

so rewrite this

(     select dtable.*, new_apps.top t1     app_detailsvvv dtable     inner join new_apps on new_apps.trackid=dtable.trackid     primarygenrename='games' , composed='1' , new_apps.top > 0 ) union (     select *, 0     app_detailsvvv dtable     primarygenrename='games' ) order t1 asc, trackname asc limit 12 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -