1 Vote Vote

Mysql ordering by joined table doesn't work

Posted by topdog 182 days ago Questions| pages page doesn work All

This is my sql query. I use it to select some data from three tables using join:

SELECT `pages`.`page_id`, `pages`.`content`
FROM (`pages`)
JOIN `comments` ON `pages`.`page_id` = `comments`.`page_id`
JOIN `meta` ON `pages`.`page_id` = `meta`.`page_id`
WHERE DAYOFMONTH ( meta.date ) = 23
AND `pages`.`category` =  '1'
ORDER BY `meta`.`visits` asc
LIMIT 25

The problem is that ordering by doesn't work if I filter posts by categories as well, e.i. if this part exists:

AND `pages`.`category` =  '1'

If I omit this part, it works fine. Any ideas?

Originally asked by: Levani on Stack Overflow

Discuss Bury


Who Voted for this Question