Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

How can I able to sort a MySQL table by two columns?

What I need are the articles sorted by the highest ratings first, then the most recent date. As an example, this would be a sample output (left # is the rating, then the article title, then the article date)

50 | This article rocks          | Feb 4, 2009

35 | This article is pretty good | Feb 1, 2009

5  | This Article isn't so hot   | Jan 25, 2009

The relevant SQL I'm using is:

 ORDER BY article_rating, article_time DESC

I can be able to sort it by one or the other, but not the both. 

1 Answer

0 votes
by (12.7k points)
edited by

The default sorting will be the ascending, you would be needing to add the keyword DESC to both your orders:

ORDER BY article_rating DESC, article_time DESC

If you want to learn more about SQL, Check out this SQL Certification by Intellipaat.

Do check out the video below

Related questions

0 votes
1 answer
asked Jan 8, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 9, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 22, 2019 in SQL by Tech4ever (20.3k points)
0 votes
3 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...