title: select from same table where two columns match and third doesn't
body: <p>I have table fedcodes with columns <code>FEATURE_NAME</code>, <code>STATE_ALPHA</code>, <code>COUNTY_NAME</code> and population data -  amongst other data. 
  I need to select all entries where <code>FEATURE_NAME</code> and <code>STATE_ALPHA</code> match, and <code>COUNTY_NAME</code> is different. I also need all data from such rows, not just those three listed. 
  Further I need to have both/all/ of such occurrences shown in output list. Please help. </p>
  
  <p>I have tried inner join but it won't work on same table. Also I have tried the following script:</p>
  
  <p><em>select fedcodes.</em>, count(<em>) num, <code>FEATURE_NAME</code>, <code>STATE_ALPHA</code> from fedcodes group by 
  <code>FEATURE_NAME</code>, <code>STATE_ALPHA</code> having num > 1 ORDER BY <code>fedcodes</code>.<code>FEATURE_NAME</code>  DESC</em></p>
  
  <p>But I don't know how to add term that <code>COUNTY_NAME</code> is not the same and it outputs only one row with num column showing number of occurrences. </p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>    ID  FEATURE_CLASS   FEATURE_ID  FEATURE_NAME    CENSUS_CODE     CENSUS_CLASS_CODE   GSA_CODE    OPM_CODE    STATE_NUMERIC   STATE_ALPHA     COUNTY_SEQUENCE     COUNTY_NUMERIC  COUNTY_NAME     DATE_CREATED    PRIMARY_LATITUDE    PRIMARY_LONGITUDE   DATE_EDITED     fips    COUNTRY_NAME    POPULATION_DATA     city_county_allocate    is_county
      146627  Populated Place     1616849     Wyandotte   88900   P1  5310    265310163   26  MI  1   163     Wayne   1980-04-14 00:00:00     42.2142064  -83.1499239     03/20/2008  26163   US  25883   100     1
      147139  Populated Place     1617956     Wyandotte   88890   U6  NULL    NULL    26  MI  1   61  Houghton    1980-04-14 00:00:00     46.8899335  -88.8754114     NULL    26061   US  0   0   0
  
      34  Populated Place     2195    Bumstead    8360    U6  NULL    NULL    4   AZ  1   13  Maricopa    1980-02-08 00:00:00     33.5733726  -112.3568269    NULL    04013   US  0   0   0
  </code></pre>
  
  <p>-As you can see from example Wyandote is in two counties hence two entries one with population data 25883 and another with population data 0 So I need both of those entries. And Bumstead is in one county only so I don't need that selected. I hope this example explain things a bit better. </p>