Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > MySQL Query Query

MySQL Query Query
Thread Tools
Senior User
Join Date: Sep 2000
Location: Glasgow, Scotland UK
Status: Offline
Reply With Quote
Dec 1, 2002, 09:57 AM
 
I'm working on my Adv Higher Computing Project and for this I'm building a web based computer registration system using PHP and MySQL. Its all going really well buy I've hit a little snag.

Basically there's a datebase with a list of all the students in the school and the information about them. There's also a column for their class. What I would like to do is for MySQL to query this table and return a list of the unique values. So in other words say there were 25 instances of Class '3' 30 instances of Class'2' and 22 instances of Class '1' how to get the datebase to return Class '3' '2' and '1'?

I tried the MySQL website and it looks like this is possible but it was in the comments section someone mentioned it and most of what was there went over my head.

Anyway if anyone has any ideas I'd be really glad to hear them cos short of creating another table of the classes which would be kludgy I can't see another way of doing this.
"You can't waste a life hating people, because all they do is live their life, laughing, doing more evil."

-ALPHA ROBERTSON,whose daughter was one of four girls killed in the bombing of a Birmingham, Ala., church in 1963.
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Dec 1, 2002, 05:18 PM
 
I've got such a crappy headcold I wish I could write a better response. But in a nutshell, you may want to research more of the keywords 'DISTINCT' 'GROUP BY' and/or 'COUNT'.

The 'DISTINCT' returns only unique values for a particular column. The 'GROUP BY' tells MySQL which column to use for the DISTINCT or COUNT if the select query is ambiguous. COUNT is great for getting a quick'n'dirty total sum of a particular column.

Wish I could be more use
Computer thez nohhh...
     
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status: Offline
Reply With Quote
Dec 1, 2002, 05:25 PM
 
Try these two things:

SELECT DISTINCT Class FROM Student ORDER BY Class
(will return a recordset of one entry for each class)

SELECT Class, COUNT(StudentID) FROM Student GROUP BY Class
(will return a recordset of one entry for each class, as well as the total count of students that are in that class)
     
ntsc  (op)
Senior User
Join Date: Sep 2000
Location: Glasgow, Scotland UK
Status: Offline
Reply With Quote
Dec 2, 2002, 01:06 PM
 
Thanks guys this is really cool!

I'll have a play with these queries tonight and see if they work.

Thanks again.
"You can't waste a life hating people, because all they do is live their life, laughing, doing more evil."

-ALPHA ROBERTSON,whose daughter was one of four girls killed in the bombing of a Birmingham, Ala., church in 1963.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:25 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2