How would I show the person logged in at the top of the list

Asked

Viewed 32 times

0

I’m trying to ride a SELECT that displays the person at the top of the list, I did so more is showing her at the end of all "SELECT * FROM usuarios ORDER BY id != ? DESC", I’ll give an example, I have a div that shows the names of people logged in example Bruno(eu), maria, rosa, joaquina etc.... I want you to show the name of the person who is always logged in above the others as I would ride this select ?

  • Per person logged in, you say only you, who is doing the query while logged in? Or all logged in to your system?

  • all logged in, for example, ta logged in Bruno and Maria, on my screen shows me above Maria, and on Maria’s screen shows her above me, understood ?

  • How is it identified that the person is logged in within the table?

1 answer

1


you can use a case.:

SELECT * 
FROM usuarios 
ORDER BY CASE 
    WHEN id == ? THEN 0
    ELSE 1
END 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.