Ding Dong
Ding Dong

Reputation: 99

Sort Sql Result By Two Order

I have a movie database and I want to get result first according year desc then movie_name desc.

here is an example.

 year       movie_name
_____________________
 2011       dil toh
 2011       no one killed
 2010       Tees maar khan
 2010       ishqiya

Now I want the out put as

dil toh
no one killed
ishqiya
Tees maar khan

So what will be the sql query ? please help me.

Every ideas are welcome. Thank you.

Upvotes: 1

Views: 100

Answers (2)

Mark Byers
Mark Byers

Reputation: 839114

I want to get result first according year desc then movie_name desc.

Try this:

SELECT movie_name
FROM yourtable
ORDER BY year DESC, movie_name DESC

But in your example the movie_names are in ascending order not descending order. To specify ascending order instead of DESC you can write ASC. Note that ASC is optional. Ascending order is the default so this will also work:

SELECT movie_name
FROM yourtable
ORDER BY year DESC, movie_name

Upvotes: 2

Ding Dong
Ding Dong

Reputation: 99

this answer is

ORDER BY `year` DESC, `movie_name` ASC

Upvotes: 1

Related Questions