简体   繁体   中英

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_id is same then, I want to fetch result order by user_job_application_date desc

在此处输入图片说明

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
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM