How to compare more than one column in an IN clause?

0

Is there a way to compare > = 2 columns in a IN clause %? type as if it were to compare objects?

For example (It will give error so the question)

SELECT * FROM Usuarios1 WHERE Nome,Sobrenome IN(SELECT Nome,Sobrenome from Usuarios2);

or it would be something like

SELECT * FROM Usuarios1 WHERE Nome,Sobrenome IN(('Leo','Bonetti'),('José','Silva'));

    
asked by anonymous 17.08.2018 / 17:10

1 answer

1

Unfortunately, there is no way to use IN to compare records by more than one column. However, you can create an anonymous table from a subquery and join the equivalent columns:

SELECT * 
FROM Usuarios1 este
INNER JOIN (
  SELECT Nome, Sobrenome 
  FROM Usuarios2) outro
ON este.Nome = outro.Nome AND este.Sobrenome = outro.Sobrenome
    
17.08.2018 / 18:34