[snip] Fascinating. But how do you build the SELECT? Seems to me you would first have to "SELECT RecordID FROM tblClass10" and then script an iteration to build the whole series of IF clauses. Or did I miss something? [/snip]
You could do that for the RecordID if you do not know what they are (I knew what RecordID's existed, so I could specifiy an IF statement for each). If I remember correctly you could even have SQL produce do the code for you. In PHP you could do it any number of ways (pseudocode follows - untested, YMMV); $query1 = "SELECT DISTINCT RecordID "; $query1 .= "FROM tblFOO "; $query2 = "SELECT RecordDate, "; $db1 = mysql_query($query1, $dbconnect) while($dbrow = mysql_fetch_object($db1)){ $query2 .= "IF(RecordID=$dbrow->RecordID,count(*),0) AS $dbrow->RecordID, "; } $query2 .= "FROM tblFOO "; $q11 .= "GROUP BY RecordDate "; Now, IF THIS WORKS (I will repeat that I have not tested it), it would be very convenient. I may have made some small syntax errors, if I get the chance I will try it later. If you try it and it works let me know. Jay Blanchard --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php