Jump to content

Query to find which field has improper entry


jajnsn

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.