Jump to content

[SOLVED] Probably a newb question but..


mistertylersmith

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.