newb Posted July 12, 2010 Share Posted July 12, 2010 ok i have a table thats setup like this: id | category | name | varset 1 | catname1 | item | 0 2 | catname2 | item | 1 3 | catname2 | item | 1 4 | catname2 | item | 1 5 | catname3 | item | 0 6 | catname3 | item | 0 7 | catname4 | item | 1 8 | catname4 | item | 1 9 | catname4 | item | 1 how can i group everything together where its varset is = 1 so its something like this: id | category | name | varset 1 | catname1 | item | 0 2 | catname2 | item | 1 5 | catname3 | item | 0 6 | catname3 | item | 0 7 | catname4 | item | 1 is this possible? how can i do this in mysql /php any help appreciated, thanks Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/ Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 Can you clarify that a little? The diagram seems unrelated to what you asked . . . Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085117 Share on other sites More sharing options...
newb Posted July 12, 2010 Author Share Posted July 12, 2010 Can you clarify that a little? The diagram seems unrelated to what you asked . . . what do u need clarified? i pretty much drew out exactly what im trying to achieve in the diagram. im just not sure as to how it should be approached through mysql. Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085118 Share on other sites More sharing options...
newb Posted July 13, 2010 Author Share Posted July 13, 2010 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085125 Share on other sites More sharing options...
jcbones Posted July 13, 2010 Share Posted July 13, 2010 In your diagram, you don't have anything grouped by the varset column. If they were grouped, then all the 1's would be at the top or the bottom. SELECT * FROM table GROUP BY varset ASC; Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085129 Share on other sites More sharing options...
newb Posted July 13, 2010 Author Share Posted July 13, 2010 well that didnt work at all... Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085132 Share on other sites More sharing options...
jcbones Posted July 13, 2010 Share Posted July 13, 2010 Well you need to explain what you want, clearly. Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085134 Share on other sites More sharing options...
newb Posted July 13, 2010 Author Share Posted July 13, 2010 whats not clear in my original post? Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085137 Share on other sites More sharing options...
isedeasy Posted July 13, 2010 Share Posted July 13, 2010 have you tried ordering by varset and id "SELECT * FROM table ORDER BY varset DESC, id" Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085138 Share on other sites More sharing options...
Pikachu2000 Posted July 13, 2010 Share Posted July 13, 2010 whats not clear in my original post? None of it is clear. That's why we're confused as to what you want to do. The diagrams make no sense in comparison to the description. Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085140 Share on other sites More sharing options...
newb Posted July 13, 2010 Author Share Posted July 13, 2010 the diagrams arent that confusing..atleast not to me.. looks pretty straightforward as to what the table looks like atm and what im trying to get it to look like. meh..looks like i just have to figure this out myself then >_< Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085145 Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2010 Share Posted July 13, 2010 To do literally what you show in your pseudo example - $query = "(SELECT * FROM your_table WHERE varset = 1 GROUP BY category) UNION (SELECT * FROM your_table WHERE varset != 1) ORDER BY id"; However I have my doubts that is really what you want in all cases with the real data, in which case you will need to use a mysql user variable to keep track of when the varset value changes in order to form groups. Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085150 Share on other sites More sharing options...
newb Posted July 13, 2010 Author Share Posted July 13, 2010 ha that's exactly what i just tried doing. that doesnt work either..but the best try in the thread Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085151 Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2010 Share Posted July 13, 2010 You do realize that the answers provided in a forum cannot be any better than the question that was asked and has already been pointed out your question and example is lacking in specifics. Also, if you don't state what "doesn't work either" in relation to your question and expected result means, no one can help you. Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085152 Share on other sites More sharing options...
newb Posted July 13, 2010 Author Share Posted July 13, 2010 fixed. had to group by varset and category Quote Link to comment https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/#findComment-1085160 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.