Reputation: 97
Im working on a search panel and I want to SELECT all the data in all columns that has this certain keyword.
usually, if you want to select something, it goes like this:
SELECT * FROM TableName WHERE columnName = "%as%";
but this only displays data that has "as" somewhere in that column I specified, I want to select all the data from all the columns that has that keyword.
here's what I want to happen:
SELECT * FROM TableName WHERE <any column> = "%as%";
please enlighten me if something like that exists. Thankyou.
Upvotes: 1
Views: 561
Reputation: 2706
you can use this trick
select
mytable.* , FROM mytable
JOIN
(
select
id,
IFNULL(col1,'')+IFNULL(col2,'')+...+IFNULL(colN,'') concatenated
FROM mytable
) T ON T.Id = mytable.Id
where t.concatenated like '%x%'
this will concat all your column in one column and you can select over this result
Upvotes: 2
Reputation: 18747
You can do this:
SELECT * FROM TableName
WHERE Col1 LIKE '%as%'
OR Col2 LIKE '%as%'
OR Col3 LIKE '%as%'
OR Col4 LIKE '%as%'
OR Col5 LIKE '%as%'
Upvotes: 2