Reputation: 269
i have one mysql database table with a column like favorite having values 1,0,0,1,0,0,1. how to get the table data with favorite =1 first after that favorite=0, please help me to solve this problem
Upvotes: 1
Views: 562
Reputation: 1234
Use this code.
SELECT * FROM TableName ORDER BY ColumnName ASC/DESC
You can refer this link. It'll be very useful.
http://thetricky.net/mySQL/GROUP%20BY%20vs%20ORDER%20BY
Thanks, Hemang.
Upvotes: 1
Reputation: 29081
IF you have only two values 0 and 1 then you can use union all query as well
SELECT * FROM tbl_name WHERE favorite = 1
UNION ALL
SELECT * FROM tbl_name WHERE favorite = 0;
Upvotes: 0
Reputation: 2900
Try this query :
SELECT favorite FROM tbl_name ORDER BY favorite DESC;
Upvotes: 3
Reputation: 166386
You need to use ORDER BY favorite DESC
in the SELECT
statement
Have a look at 3.3.4.4. Sorting Rows
Upvotes: 3