jx2 - Thanks for your reply. As I understand the GROUP BY parameter (including GROUP BY WITH ROLLUP) it will only work if there is an aggregate function in the query. Since I want all lines to be echo'd I don't want to have an aggregate function.
pbmods - Yes and No, but mostly
yes. :)
Quote:
There's a definite pattern here; between any two rows in the same section, either the serial number is the same, or the category is the same.
Yes, thats exactly right. In the following example (as used previously) there are 3 groups, lets call them A, B, C. In group A line 4 doesn't have either the same serial or category as the line directly above it. It does however have the same category as another record from that that group, line 2.
-
Toronto Ontario Chef 12345 ABC
-
Detroit Michigan Cook 12345 DBF
-
Toronto Ontario Cook 12353 ABC
-
Detroit Michigan Janitor 33333 DBF
-
NYC New York Chef 33333 JKL
-
-
Los Angeles California Waiter 12355 DGG
-
NYC New York Janitor 12382 DGG
-
-
Miami Florida Cook 12777 FGH
-
Fort Worth Texas Usher 12777 QWE
-
Dallas Texas Cook 22222 FGH
Similarly, in Group C, line 12 doesn't have the same serial or category as the line above it, but the category matches that of line 10.
Quote:
It seems like (and correct me if I'm wrong) MySQL is returning the results in the proper order
Not quite. The results are set to ORDER BY serial, which means that they'll all be grouped together, but the category column is not grouped together.
If I just use the following code as I currently am I could get 5000 results, and while they're sorted by serial, result/line 126 could have the same category as result 3456. Because line 126 has the same category as line 3456 they should be grouped together.
[PHP]
$result = mysql_query("SELECT city, state, title, serial, category FROM serials ORDER BY serial, category");
[/PHP]
Quote:
Would there be a situation where at least one of the criteria matches, but we should start a new section anyway?
No.
Quote:
And/or are there circumstances where even though neither the serial nor the category matches, but we should still keep the two rows in the same section?
No.
I just can't seem to wrap my head around how you'd group results based on either of two variables.
Thanks soooo much for your help so far!