Skip navigation links

MySQL Forums :: Newbie :: order by 2 columns


Advanced Search

order by 2 columns
Posted by: avancha mailto ()
Date: November 01, 2012 09:18PM

here is a query I am working on
SELECT i.*,
CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams
FROM mc23r_k2_items as i
LEFT JOIN mc23r_k2_categories AS c
ON c.id = i.catid
WHERE i.published = 1
AND i.access IN(1,1)
AND i.trash = 0
AND c.published = 1
AND c.access IN(1,1)
AND c.trash = 0
AND ( i.publish_up = '0000-00-00 00:00:00' OR i.publish_up <= '2012-11-02 02:49:48' )
AND ( i.publish_down = '0000-00-00 00:00:00' OR i.publish_down >= '2012-11-02 02:49:48' )
AND c.id IN (1,2,3,4)
ORDER BY c.ordering, i.ordering
LIMIT 0, 100


I am complete newbie to joins and advanced stuff..
The result of the above query is returning catid as follows:
c.ordering: 2 1 2 1 2 1 2 2 2 3 3 3 4 4 4 4 4
i.ordering: 1 1 2 2 3 3 4 5 6 1 2 3 1 2 3 4 5

I am looking for order as
1 1 1 2 2 2 2 2 2 3 3 3 4 4 4 4 4
1 2 3 4 1 2 3 4 5 6 1 2 3 4 5 6 7

What change should I do to the query please. Only c.ordering columns 1 and 2 is the point of conflict rest of the pattern is good.

Thanks



Edited 2 time(s). Last edit at 11/01/2012 09:58PM by avancha mailto.

Options: ReplyQuote


Subject Written By Posted
order by 2 columns avancha mailto 11/01/2012 09:18PM
Re: order by 2 columns laptop alias 11/02/2012 01:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.