 |
 |
MySQL Query Query
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: Glasgow, Scotland UK
Status:
Offline
|
|
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
|
|
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
|
|
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)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: Glasgow, Scotland UK
Status:
Offline
|
|
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.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |