Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/207547-group-only-certain-columns-together/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.