如何从mysql数据库中按特定顺序获取数据

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

You need to use ORDER BY favorite DESC in the SELECT statement

Have a look at 3.3.4.4. Sorting Rows

Try this query :

SELECT favorite FROM tbl_name ORDER BY favorite DESC;
SELECT * FROM `<tablename>` order by favorite DESC;

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;

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.