Reputation: 151
I have a query like this. I would like to filter with column Name "A.
select 'DummyValue1' as ColumnNameA
from TableT.
Now I would like to apply filter like
select 'DummyValue1' as ColumnNameA
from TableT
where ColumnNameA = "Value1" .
How do I do it in Oracle.
Please note here 'DummyValue1' as ColumnNameA is not actually a database column. I am just creating in my result set.
Upvotes: 3
Views: 2300
Reputation: 92785
You can't use an alias in WHERE
clause because of the query processing order. But you can use an outer select or CTE for something like that
SELECT t.*
FROM
(
SELECT 'DummyValue1' as ColumnNameA, ...
FROM TableT
) t
WHERE ColumnNameA = 'Value1'
Here is SQLFiddle demo
Upvotes: 4
Reputation: 27251
The structure of the query remains the same, only the string literal in the WHERE
clause of the query need to be enclosed in single quotes, because string literal, in Oracle, that enclosed in double quotes will be considered as identifier:
select 'DummyValue1' as ColumnNameA
from TableT
where ColumnNameA = 'Value1'
Upvotes: 2
Reputation: 2783
If I understand correctly, this should work:
SELECT ColumnNameA as 'DummyValue1'
FROM TableT
WHERE ColumnNameA = 'Value1'
Upvotes: 0