Shubham Mishra
Shubham Mishra

Reputation: 114

MySQL - Query to order by second column if first column value is same

SELECT * 
FROM `user_job_application` 
ORDER BY `user_job_application`.`user_id` DESC

It gives the table result like image preview. but when user_idis same then, I want to fetch result order by user_job_application_date desc

enter image description here

Upvotes: 2

Views: 1552

Answers (2)

Dobermann
Dobermann

Reputation: 1

SELECT * FROM `user_job_application`
ORDER BY `user_job_application`.`user_id` DESC,
         `user_job_application`.`user_job_application_date` DESC;

Just put a comma after your DESC and add the next ORDER BY item.

Upvotes: 0

DineshDB
DineshDB

Reputation: 6193

We can ORDER results using multiple columns.

Try this:

SELECT * 
FROM `user_job_application` 
ORDER BY `user_job_application`.`user_id` DESC, user_job_application_date desc

Upvotes: 8

Related Questions