Search code examples
mysqlsqlphpmyadminresultsetunique-values

MySQL return set if values don't exist


Let's say I have 5 rows, containing the following:

ID     KEY       VALUE
1      address   123 Main Street
1      latlng    (111.139, 111.238)
2      address   45 South Street
3      address   67 North Ave
3      latlng    (448.002, 100.301110)

Now, if I wanted to return ONLY the row that did NOT contain a corresponding latlng row to accompany the address (ie, ID 2) how would I go about doing that with a mySQL statement?

This one has me stumped!!


Solution

  • SELECT *
    FROM TABLE
    WHERE ID NOT IN
    (SELECT ID FROM TABLE WHERE KEY = 'LATLNG')