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 Quote 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 Quote 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? Quote 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` = '' Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/132550-solved-query-group-by/#findComment-689497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.