开发者

searching concat value

开发者 https://www.devze.com 2023-04-04 19:13 出处:网络
i have problem in searching concat values, is there any ways using \"mysql query\" or \"php al开发者_如何学Gogorithm\" ??

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%'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号