How to compare 2 Cells in different columns - SQL

1

I need to make a SELECT looking for some data with the proviso that only if the value of a certain cell is different from another cell .

Ex:

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

I would like a SELECT that only searches for 2nd row , where Val1 is different from Val2.

    
asked by anonymous 25.01.2017 / 20:38

2 answers

1

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

select * from tabela where val1 <> val2
    
25.01.2017 / 20:42
0

Try using the different operator !=

SELECT * FROM nome_tabela WHERE Val1 != Val2
    
25.01.2017 / 20:50