i have 1 table in that i want to reorder the views column using alter function in my php file basically it should be reorder in most views to least views order.and want it to display in same order has altered but it is showing in order of id.
Now here i dont want to use ORDER BY views DESC thats why i am using alter function. because i am using ORDER BY name ASC already in my php file.
TABLE => users
id | name | views
1 | user1 | 700
2 | user3 | 900
3 | user1 | 200
4 | user4 | 900
5 | user4 | 800
6 | user4 | 800
7 | user3 | 900
8 | user4 | 900
9 | user5 | 100
10 | user5 | 100
// this is random table..//
ULtimately i am looking for that when by table is in views ORDERED then i will select data from table and if there are same name then it should be order in views as ALTERED so that i get ouptup like this :
id | name | views
1 | user1 | 900
2 | user1 | 700
3 | user1 | 200
4 | user3 | 900
5 | user4 | 900
6 | user4 | 800
7 | user5 | 900
8 | user5 | 900
9 | user5 | 300
10 | user5 | 100
SQL tables are unordered sets. They have no intrinsic order, and you should never rely on any order returned from queries that don't explicitly state an order by
clause. In your case, it seems you need two elements in the ordering - first by name, and then by views:
SELECT *
FROM mytable
ORDER BY name ASC, views DESC
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.