Need help

Here is my current code:

SELECT *
FROM classes, students
WHERE classes.session = 1 AND classes.time = 9 AND students.studentnumber = colname2 AND classes.count < 13 AND classes.grade1 = students.grade or classes.grade2 = students.grade or classes.grade3 = students.grade

what i want to do is take the classes.count < 13 to instead of having classes.count do a live count on the data to see if i have 13 or more.

Please Help!

THanks!

is COUNT an actual field in the table of CLASSES?

I do have a field called count i was going have it add +1 but would rather just pull it earlier on… by counting occurences and having that implemented in the actual query for the data. Idea is if it occurs 13+ times not to show in a dropdown box

Having a field called COUNT could present problems since COUNT is a FUNCTION used by MOST SQL type servers.

If you wanted to know if you have “Exceeded” the COUNT you can do a query such as

SELECT COUNT(SomeFieldInTable)
FROM table(s)
WHERE conditions

For examle

SELECT COUNT(studnetnumber) FROM students, classes
WHERE classes.session = 1 AND classes.time = 9 AND students.studentnumber = colname2 AND classes.grade1 = students.grade or classes.grade2 = students.grade or classes.grade3 = students.grade

This will return a SINGLE value which is HOW MANY times a record appears matching the WHERE clause.

You can then determine, based on that result, what to do next.

As stated above, you should probably avoid using names that match functions as database, table, or column names such as COUNT, SUM, GROUP, ORDER, etc… as well as the “RESERVED” Words (see http://dev.mysql.com/doc/refman/4.1/en/ … words.html ). Instead consider a variation of these words such as CLASSCOUNT, CLASSSUM, GROUPNAME, ORDEREDITEMS, etc…

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service