Jeff Pflueger wrote:
Hi. Thanks for any help on this. I've been beating my head over it for hours. Here's what I am trying to do: I have four tables I am joining via a unique key (Fellow_id). The results I want to group into three categories, each alphabetized within the group.

Is this too much to do in a single query? I am very close, but not there yet.

Here's the query:
SELECT
(...)
   GROUP BY
   graduate_results_INSTITUTIONS.UNKNOWN ASC,
   graduate_results_INSTITUTIONS.END ASC,
   Fellowships.Fellowship_id
I want to alphabetize each group with something like: ORDER BY Fellow_contact.Fellow_2nd_name


Perhaps the use of GROUP BY is not entirely clear to you; if you GROUP BY a field then each distinct value for that field will result in a single output row. If there were originally 20 records for a single field value you can use functions such as COUNT(), SUM(), etc. to calculate values for the GROUP. Example: you want to know how many times duplicate e-mail addresses are present in a table:
SELECT `email`, COUNT(`email`) FROM `table1` GROUP BY `email`;
---------------------
email      count
---------------------
[EMAIL PROTECTED]      5
[EMAIL PROTECTED]      2
[EMAIL PROTECTED]      1
---------------------

" If you use GROUP BY, output rows are sorted according to the GROUP BY columns as if you had an ORDER BY for the same columns. MySQL has extended the GROUP BY clause as of version 3.23.34 so that you can also specify ASC and DESC after columns named in the clause."

Maybe you want to have nested ORDER BY's. Sort by city, within each city sort by street, within each street sort by number of tv-sets:
SELECT (....) ORDER BY `city` ASC, `street` ASC, `num_tv` DESC;

Regards, Jigal.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to