如果值不存在,则返回MySQL

时间:2013-12-19 18:05:05

标签: mysql sql phpmyadmin resultset unique-values

假设我有5行,包含以下内容:

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)

现在,如果我只想返回不包含相应latlng行的行来附加地址(即ID 2),我将如何使用mySQL语句执行此操作?

这个让我难过!!

2 个答案:

答案 0 :(得分:1)

尝试类似

的内容
SELECT t1.*
FROM Table t1
    LEFT OUTER JOIN Table t2 ON t1.id = t2.id
WHERE t1.Key = 'latlng' AND t2.Key = 'address' AND t2.id IS NULL

答案 1 :(得分:1)

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