While the query "WHERE expr LIKE '%$user%'" works without fail, it can
not use an index, and thus on large tables will be exceedingly slow.
mysql> explain select last, first from users where concat(last,first)
like '%user%'\G
*** 1. row ***
I do this all the time and it works flawlessly. Just like your example and even
more extreme. I use this technique to provide search mechamisms for my
applications. ex,
SELECT ID
FROM table
WHERE concat(field1, field2, field3,...{all the fields in the table}) Like
'%searchstring%';
This w
s in the first
> and last name columns
> 'Billy Ray' Smith and John 'Von Hoenhiem' would cause problems
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Thursday, June 23, 2005 4:05 PM
> To: Matt Babineau
> Cc: my
5 PM
To: Matt Babineau
Cc: mysql@lists.mysql.com
Subject: Re: How to SELECT something (CONCAT) and search the field
Hi,
what's your version ? in 4.11 the two forms work :
mysql> select concat(firstname,' ','lastname') from names;
+---
sorry for the first select (bad copy of a string 'lastname'):
mysql> select concat(firstname,' ',lastname) from names where concat(firstname,'
',lastname) like 'Jean Dupond%';
++
| concat(firstname,' ',lastname) |
++
| Jean Dupond
Hi,
what's your version ? in 4.11 the two forms work :
mysql> select concat(firstname,' ','lastname') from names;
+--+
| concat(firstname,' ','lastname') |
+--+
| Jean lastname|
+--+
select first_name, lastname from user where
first_name like '%$user%'
or
last_name like '%$user%'
;
--- Matt Babineau <[EMAIL PROTECTED]> wrote:
> Hey All-
>
> Got a fun question - I hit the manual but not much
> luck on my question. I
> want to combine 2 fields and then search them
>
> SE