Reputation: 8511
I need to combine 2 columns and find whether the combined content matches something. However the following query doesn't work:
select
concat(column1,column2) as combined_column
from
my_table
where
combined_column like '%value%';
MySQL reports an error that 'combined_column' doesn't exist. How to solve this problem?
Upvotes: 0
Views: 104
Reputation: 2460
select
concat(column1,column2) as combined_column
from
my_table
where
Concat(column1,column2) like '%value%';
Upvotes: 3
Reputation: 22162
You should replace your where clausole with this one:
where concat(column1,column2) like '%value%';
Explanation: The where clausole isn't able to read the var named in the SELECT
.
Upvotes: 3