How can I keep my records grouped together using SQL?

edlinux

New Member
Suppose I have a GAME table with the following fieldsmatch_id, user_id, resultThe results always come in pairs with identical match_id. So for example\[code\]1837, 4, Win1837, 29, Forfeit\[/code\]I would like to separate into two groups, one group that has results and one group that doesn't. This is pretty easily done by using \[code\]WHERE result <> ''\[/code\]However I've noticed a few strange records such as the following\[code\]1839, 5, Win1839, 40,\[/code\]The second record does not have a result recorded against it. Therefore using \[code\]result <> ''\[/code\] puts splits match 1839 into two separate groups whereas I want them to stay together. Can I achieve this in SQL?So basically my pseudo code is:if both have a resultFirst groupIf either have the resultFirst groupIf none have a resultSecond groupFull code using MySQL\[code\]SQL1: SELECT * from GAME where result <> ''\[/code\]Gives \[code\]1837, 4, Win1837, 29, Forfeit1839, 5, WinSQL2: SELECT * from GAME where result = ''1839, 40,1850, 30,1850, 5,\[/code\]I'm looking forSQL1: ??\[code\]1837, 4, Win1837, 29, Forfeit1839, 5, Win1839, 40,\[/code\]SQL2: ??\[code\]1850, 30,1850, 5,\[/code\]
 
Top