selectproducts.*fromproductsinnerjoinprioritiesonproducts.category=priorities.categoryorderbypriorities.priorityisnull,-- this to put null values at the end, or use 'is not null' to put null at firstpriorities.priority,products.id-- or some other field
或者在 rails 里
.where(true).order("personal_messages.read_at is not null").order("personal_messages.id DESC")#未读消息(阅读时间为null)在最前,其余以id倒序