Jump to content

Recommended Posts

mysql version: 5.0.41-community-nt

 

Desired $result from query: Some desired information about users in specific groups.  Groups are identified by the combination of class_letter and class_group.. ex a1, b1, c1, a2, b2, c2, ect..

 

The Problem:

1. To sort the records in such a way that users of similar groups are clustered. ex user1, user24, and user3 are all members of group a1 or rather: `class_letter` = 'a' AND `class_group` = 1;.

 

2.The groups are ordered in ascending class_groups.. ie a2 would never precede any group that had a 1 at the end [a1, f1, z1, ect...]

 

3. Finally, the users are ordered by ascending last names. (but only within their specific groups ie. the users of a1 are sorted alphabetically then the users of group b1 are sorted alphabetically ect..)

 

 

 

show create table....

CREATE TABLE `users` (\n  `user_id` int(11) NOT NULL auto_increment,\n  `username` varchar(50) NOT NULL,\n  `first_name` varchar(20) NOT NULL,\n  `last_name` varchar(20) NOT NULL,\n  `password` varchar(50) default NULL,\n  `headshot_location` varchar(150) default NULL,\n  `quote` text,\n  `concentration` varchar(50) default NULL,\n  `year` enum('Freshman','Sophomore','Junior','Senior') default NULL,\n  `class_letter` enum('Alpha','Beta','Gamma','Delta','Epsilon','Zeta','Eta','Theta','Iota','Kappa','Lambda','Mu','Nu','Xi','Omicron','Pi','Rho','Sigma','Tau','Upsilon','Phi','Chi','Psi','Omega') NOT NULL,\n  `class_group` int(11) NOT NULL,\n  PRIMARY KEY  (`user_id`),\n  UNIQUE KEY `nick_name` (`username`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1

 

 

this is the code i have so far, however it does not work... as far as i can tell it only groups the records in the way in which i describe...

if i have missed any part of the posting guidelines, please kindly correct me and i will try to comply in the future

SELECT `user_id` , `first_name` , `last_name` , `headshot_location` , `quote` , `concentration` , `class_letter` , `class_group`'
FROM `users`
GROUP BY `class_letter` , `class_group` ASC
ORDER BY `last_name`

Link to comment
https://forums.phpfreaks.com/topic/84792-solved-probably-a-newb-question-but/
Share on other sites

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.