user3633580
user3633580

Reputation: 93

Oracle - Concatenate Field on Where

I'm using a Concatenate Field and I'd like to use it on the WHERE of it

TABLE T_EXAMPLE
RED - FERRARI - F50
BLUE - PORSHE - S20  
GREEN - CAMARO - T40

I have to show all this fields on a Grid, 'cause of this that I need to put all of them in one field, but I have to filter the Grid with One information that can be any one of the three, example:

SELECT
  T.COLOR || T.CAR,T || T.Model AS FIELD1
FROM T_EXAMPLE T
WHERE FIELD1 LIKE '%FER%'

Here I want to filter the Ferrari, but I've tried to do like this but I got an error (Invalid Identifier).

Can anyone help me??

Upvotes: 2

Views: 2022

Answers (1)

sstan
sstan

Reputation: 36473

The alias FIELD1 can't be used in the WHERE clause, so just repeat the column concatenation in the WHERE clause. Like this:

SELECT
  T.COLOR || T.CAR || T.Model AS FIELD1
FROM T_EXAMPLE T
WHERE T.COLOR || T.CAR || T.Model LIKE '%FER%'

Or, if you don't like the repetition, another option would be this:

SELECT FIELD1
FROM (
  SELECT
    T.COLOR || T.CAR || T.Model AS FIELD1
  FROM T_EXAMPLE T
)
WHERE FIELD1 LIKE '%FER%'

Upvotes: 2

Related Questions