MYSQL - Select is not working properly

1

Good evening,

I have below the search in the database, but it returns me error or does not work on line 4 where it says "JOIN contracts co ON c.email! = co.email", has how to do otherwise, or improve the search? Thanks

SELECT os.osID, c.nome, c.email, os.idioma, os.dataAtualizacao
    FROM os
JOIN cadastroCliente c ON os.idcliente = c.cadastroClienteID AND c.email != ''
JOIN contratos co ON c.email != co.email
    WHERE os.status = '1' 
    AND os.respondido = '1'
    AND os.emailAutRecuperar1 = '0'
    AND os.dataAtualizacao < CURRENT_DATE()-3
GROUP BY osID
    
asked by anonymous 27.09.2015 / 00:29

1 answer

1

This sign: != , does not exist in standard SQL syntax. There is even an entry in the MySQL manual with this , but the recommended one, even by approaching ANSI SQL, is to use <> , common to all SQL interpreters of any relational technology.

It is also important to check that c.email is not null. Anything compared to null gives false except is not null .

The correct one would be:

SELECT os.osID, c.nome, c.email, os.idioma, os.dataAtualizacao
    FROM os
JOIN cadastroCliente c ON os.idcliente = c.cadastroClienteID AND c.email <> '' and c.email is not null
JOIN contratos co ON c.email <> co.email
    WHERE os.status = '1' 
    AND os.respondido = '1'
    AND os.emailAutRecuperar1 = '0'
    AND os.dataAtualizacao < CURRENT_DATE()-3
GROUP BY osID
    
27.09.2015 / 01:16