SQL Query with Typo not working in MySQL (Order by on calculated field) -
i have query in 1 of column calculated one. every thing working except not ordering results when use calculated column in query. query large 1 have simplified below understanding. here calculated column "remaining"
select t1.id, t1.name, t2.duration - datediff(now(), t1.posting_time) "remaining" table1 t1, table2 t2 td.id = t1.timefield order id, name, remaining desc
even if remove "remaining" order clause or use asc or desc, nothing happens , order stays same.
the time when 'remaining' alters sort order when id , name in 2 rows same. otherwise, has no effect on ordering.
you need fix typo of 'td.id
' 't2.id
'.
you should learn join notation too:
select t1.id, t1.name, t2.duration - datediff(now(), t1.posting_time) "remaining" table1 t1 join table2 t2 on t2.id = t1.timefield order id, name, remaining desc
Comments
Post a Comment