samedi 27 juin 2015

Advanced mysql query which sort down specific records on result set irrespective of its default sorting?

I have a query which actually have a sorting using order by clause. i have a table like following...

user_id   user_name   user_age   user_state   user_points 
1         Rakul       30         CA           56
2         Naydee      29         NY           144
3         Jeet        40         NJ           43
.....

i have following query...

select * from users where user_state = 'NY' order by user_points desc limit 50;

This gives me the list of 50 people with most points. I wanted to give least preference to few people who's id's were known. Incase if i do not have enough 50 records then those id's should come in the last in the list. I do not want the users 2 and 3 to come on top of the list even though they have higher points... those people should come on the last of the list from the query. Is there any way to push specific records to last on result set irrespective of query sorting ?

Aucun commentaire:

Enregistrer un commentaire