我想在多个字段中搜索相同的值。但逃脱最后一次事件的铭文。有可能吗?
我尝试了以下内容,但没有成功。
SELECT id, login
FROM PERSON
WHERE login like '%toto%'
OR nickname like '%toto%'
OR name like '%toto%'
AND id NOT IN (
SELECT p.id
FROM PERSONNE p, INSCRIPTION i, EVENT e
WHERE p.id = i.id_person
AND i.id_event = e.id
AND i.id_event = (
SELECT MAX(id) FROM EVENT))
GROUP BY login, nom, pseudo
答案 0 :(得分:5)
您只需要对OR
条件进行分组。
SELECT id, login
FROM PERSON
WHERE (login like '%toto%' OR nickname like '%toto%' OR name like '%toto%')
AND id NOT IN (SELECT p.id FROM PERSONNE p, INSCRIPTION i, EVENT e
WHERE p.id = i.id_person
AND i.id_event = e.id
AND i.id_event = (SELECT MAX(id) FROM EVENT))
GROUP BY login, nom, pseudo