How to compare 2 cells in different columns - SQL

Asked

Viewed 888 times

1

I need to make a SELECT searching some data with the condition that only if the value of a given cellis different from another cell.

Ex:

+-----------+------+------+
| Descricao | Val1 | Val2 |
+-----------+------+------+
| hhhhhhhhh | 9999 | 9999 |
| yyyyyyyyy | 1111 | 2222 |
+-----------+------+------+

Would like a SELECTonly to seek the 2nd row, where Val1 is different from Val2.

  • As Marlon mentioned, the ideal is to use Where >select * from table Where val1 <> val2

2 answers

1


Just use on condition (where) a comparison operator between columns.

select * from tabela where val1 <> val2

0

Try to use different operator !=

SELECT * FROM nome_tabela WHERE Val1 != Val2

Browser other questions tagged

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