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

Asked

Viewed 43 times

0

There is a way to compare >= 2 columns in a clause IN kind of like comparing objects?

For example(Will give error so the question)

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

or something like

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

1 answer

1


Unfortunately, there’s no way to use the IN to compare records by more than one column. However, you can create an anonymous table from a subquery and make a Join in 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.