searching concat value
i have problem in searching concat values,
is there any ways using "mysql query" or "php al开发者_如何学Gogorithm" ?? my idea is,, i have four column to combine (concate) as ID field and NAME field. using this two field, actualy i have an input text to use for searching this two field (ID and NAME) i have query like this but this doesn't work (because of this line: id like '%$search%')select
concat(
id_1, '.',
id_2, '.',
id_3, '.',
id_4
)
as id,
name
from
employee
where
id like '%$search%'
or name like '%$search%'
"id" hasn't been prepared yet when the WHERE clause is applied
So use a derived table:
select
id, name
FROM
(
select
concat(
id_1, '.',
id_2, '.',
id_3, '.',
id_4
)
as id,
name
from
employee
) as intermediate
where
id like '%$search%'
or name like '%$search%'
or repeat the expression
select
concat(
id_1, '.',
id_2, '.',
id_3, '.',
id_4
)
as id,
name
from
employee
where
concat(
id_1, '.',
id_2, '.',
id_3, '.',
id_4
) like '%$search%'
or name like '%$search%'
精彩评论