jajnsn Posted November 30, 2011 Share Posted November 30, 2011 This pertains to MYSQL 5.0. I have a table that has several columns, including Institution_Name and InstNo. Each distinct Institution_Name is supposed to have a distinct InstNo. Therefore, a count of Institution_Name should equal the count of InstNo. However, when I run SELECT COUNT(distinct Institution_Name) the count returned is 221 and when I run SELECT COUNT(distinct InstNo), the value returned is 219. The 221 count is correct which means, I think, that one or more institutional name entries are erroneously associated with more than one institutional number. I'm at a loss as to how to write a query that finds this error. The problem has my head is about to sizzle. Help please! Quote Link to comment Share on other sites More sharing options...
mikosiko Posted November 30, 2011 Share Posted November 30, 2011 the simplest way SELECT Institution_name, COUNT(InsNo) FROM <your_table_here> GROUP BY Institution_name HAVING COUNT(InsNo) > 1 Quote Link to comment Share on other sites More sharing options...
jajnsn Posted November 30, 2011 Author Share Posted November 30, 2011 Thanks Mikosito, The command you provided is excellent. I failed to state that the distinct values in Institution_Name and InstNo repeat hundreds of times in rows distinguished by data in other fields. This means that the counts returned by the query for InstNo were too high for me to detect where the problem lay. Fortunately, I had another table that contained all 221 institutional numbers. So, I solved the problem with a query of which of the institutional numbers in that table were not coming up in my distinct counts on the faulty table, and I need a cold drink of mineral water. Peace! 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.