MySql Order By Field for Custom Order By

by Sasikumar 2014-07-25 13:16:28

MySql Order By Field can be used for custom ordering of data
MySql Query :

SELECT * FROM site ORDER BY FIELD(status, 'active','suspended','rejected');

Table Schema :

CREATE TABLE site (`id` int, `name` varchar(40), `status` varchar(15)) ;
	
INSERT INTO site (`id`, `name`, `status`)
VALUES (1, 'hiox.org', 'active'),
	(2, 'hiox.com', 'rejected'),
	(3, 'hibihi.com', 'suspended'),
	(4, 'hscripts.com', 'active'),
	(5, 'hioxindia.com', 'rejected'),
	(6, 'bforball.com', 'suspended'),
	(7, 'jqslider.com', 'active'),
	(8, 'easycalculation.com', 'active');
Table Structure :

Output :
output
On executing the above query we get this ouput. This helps in custom ordering when ASC and DESC are not applicable.


"ORDER BY FIELD" is a useful mysql statement which helps in custom ordering of data. This can be used to order field.
772
like
0
dislike
0
mail
flag

You must LOGIN to add comments