onedumbcoder Posted May 27, 2009 Share Posted May 27, 2009 Is it possible to have an if statement inside a query? something like this: SELECT IF type = 0 THEN 'car' AS t ELSEIF type = 1 THEN 'bike' AS t FROM machine WHERE ownser='mike' Link to comment https://forums.phpfreaks.com/topic/159797-if-statement-inside-a-query/ Share on other sites More sharing options...
corbin Posted May 27, 2009 Share Posted May 27, 2009 http://dev.mysql.com/doc/refman/5.0/en/case-statement.html Link to comment https://forums.phpfreaks.com/topic/159797-if-statement-inside-a-query/#findComment-842885 Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 SELECT IF(type=0,'car','bike') AS t FROM machine WHERE ownser='mike' That should work. Link to comment https://forums.phpfreaks.com/topic/159797-if-statement-inside-a-query/#findComment-842890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.