Home > Net >  Why not show my results when i use not squeal with and
Why not show my results when i use not squeal with and

Time:08-20

Why not show my results when i use not squeal with and in this case

SELECT 
'999' as A,
'999' AS B,
'000' AS C,
'000' as D
WHERE
A <> '999'
and B <> '999'
and C <> '999'
AND D <> '999'

This terminal results enter image description here

CodePudding user response:

Basically, we can't use WHERE clause to filter the column that dynamically evaluates. Try to use HAVING instead.

SELECT 
'999' as A,
'999' AS B,
'000' AS C,
'000' as D
HAVING
A <> '999'
and B <> '999'
and C <> '999'
AND D <> '999'

CodePudding user response:

May be because you have set the values for A,B,C,D and sql processor does not see any ones. And you use 'AND' - so it means that the condition should be resolved only together, for all values. So that is why you don`t see C and D.

CodePudding user response:

You would need to implement a derived table such as:

select A, B, C, D
from (
    select 
    '999' as A,
    '999' as B,
    '000' as C,
    '000' as D
)t
where
A <> '999'
and B <> '999'
and C <> '999'
and D <> '999';
  •  Tags:  
  • sql
  • Related