SELECT DISTINCT [a]
,[b]
FROM [Compara] -- 1 °
SELECT [a]
,[b]
FROM [Compara]
WHERE [a] = [b] --2°
There was no return, so I do not know if I did it right or wrong, if someone can help me.
SELECT DISTINCT [a]
,[b]
FROM [Compara] -- 1 °
SELECT [a]
,[b]
FROM [Compara]
WHERE [a] = [b] --2°
There was no return, so I do not know if I did it right or wrong, if someone can help me.
Follows:
SELECT CASE WHEN A = B THEN 'Coluna A igual a B' ELSE 'Coluna A diferente da B' END AS COMPARATIVO_01
FROM TABELA
The SELECT
above will return all the data in the table (since I did not use WHERE
), but in return, it will return if the records in column A are different from those in column B, compared to row.
Now if you just want to return the records where the A
column is different from B
, use the statement below:
SELECT *
FROM TABELA
WHERE A <> B;
Or to find out if they are the same:
SELECT *
FROM TABELA
WHERE A = B;
Edited
I put all three conditions to make clear to the user the possible possibilities of SQL.
Attention: As you said you are still learning SQL
, be careful not to compare different columns of data. How to compare TRUE
or FALSE
with VARCHAR
.