Wednesday, March 24, 2010

Special MySQL Query : Control Statement in Query , CASE CONDITION, IF CONDITION

SELECT CASE `parent_id` WHEN '0' THEN `name` ELSE `id` END AS `resumt` FROM `categories` LIMIT 0 , 30
==============================================================================

SELECT * FROM categories WHERE id =40 ORDER BY CASE WHEN image IS NULL THEN id ELSE parent_id END LIMIT 0 , 30
==============================================================================

SELECT * FROM categories order by CASE WHEN (select `image` from `categories` where `id` = '40') IS NULL THEN id ELSE parent_id END
==============================================================================

http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home