drakal30 Posted November 13, 2007 Share Posted November 13, 2007 I have a table that has data about devices that have had issues, these devices are grouped by what we call Bank Number, I want to find and display the bank number that has been entered the most in the table. I was thinking of using the MAX function but this doesn't seem to be working properly for me. Any Ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 13, 2007 Share Posted November 13, 2007 SELECT bank_number, COUNT(*) as occurs FROM issues GROUP BY bank_number ORDER BY occurs DESC LIMIT 1 Quote Link to comment Share on other sites More sharing options...
drakal30 Posted November 13, 2007 Author Share Posted November 13, 2007 Thanks I tried that but I am getting a NULL return Here is my code. $query = "SELECT tBankNum,COUNT(*) as occurs FROM tMachIssue WHERE DATE_FORMAT(FROM_UNIXTIME(tDate),'%Y') = $tempDate GROUP BY tBankNum ORDER BY occurs DESC LIMIT 1"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $maxBank = $row['occurs']; Quote Link to comment Share on other sites More sharing options...
drakal30 Posted November 14, 2007 Author Share Posted November 14, 2007 Never mind It was an error on my part, it works great! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.