3

我想在多个字段中搜索相同的值。但为最后一个事件逃脱铭文。是否可以?

我尝试了以下方法,但没有成功。

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
4

1 回答 1

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
于 2013-03-07T00:38:04.947 回答