Canman2005 Posted November 13, 2008 Share Posted November 13, 2008 Hi all I have a simple database, looks like name type David 123 Richard 123 Sarah Harry 999 Bob Brian 999 Is it possible to do a QUERY (LIMITING to 3) and get all rows returned, but do a GROUP BY if any of the rows returned have matching `type` values, so it would looks like name type David 123 Sarah Harry 999 Bob Can anyone help? Thanks Dave Link to comment https://forums.phpfreaks.com/topic/132550-solved-query-group-by/ Share on other sites More sharing options...
Canman2005 Posted November 13, 2008 Author Share Posted November 13, 2008 Is it possible to do something like GROUP BY `type` IF `type` != '' that way it would group anything which has the same `type` value Link to comment https://forums.phpfreaks.com/topic/132550-solved-query-group-by/#findComment-689296 Share on other sites More sharing options...
Canman2005 Posted November 13, 2008 Author Share Posted November 13, 2008 can anyone help? Link to comment https://forums.phpfreaks.com/topic/132550-solved-query-group-by/#findComment-689464 Share on other sites More sharing options...
Barand Posted November 13, 2008 Share Posted November 13, 2008 something like SELECT `name`, `type` FROM mytable WHERE `type` <> '' GROUP BY `type` UNION SELECT `name`, `type` FROM mytable WHERE `type` = '' Link to comment https://forums.phpfreaks.com/topic/132550-solved-query-group-by/#findComment-689491 Share on other sites More sharing options...
Canman2005 Posted November 13, 2008 Author Share Posted November 13, 2008 You are a dimond Thanks mate Link to comment https://forums.phpfreaks.com/topic/132550-solved-query-group-by/#findComment-689497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.