[nycphp-talk] MySQL query question
DeWitt, Michael
mjdewitt at alexcommgrp.com
Tue Nov 16 11:55:47 EST 2004
Joel,
Thanks for your help. I found that mysql treats column names embedded in
strings as a literal. I could get right hand like to work using:
select * from table where firm like rtrim(last_name)+'%%%'
but couldn't find a syntax that worked for the left hand side. The problem
was that it was over matching (and yet not returning all rows).
for example this query:
select * from table where firm like '%%%'+rtrim(last_name)+'%%%'
returned about 90% of all rows and clearly was overmatching.
The solution I found which seems to duplicate the the sql server query is :
select count(*) from nar where locate(rtrim(lcntct),firm)>0;
Thanks again.
Mike
> -----Original Message-----
> From: Joel De Gan [SMTP:joel at tagword.com]
> Sent: Tuesday, November 16, 2004 6:16 AM
> To: NYPHP Talk
> Subject: Re: [nycphp-talk] MySQL query question
>
> Hi,
> In like comparisions you can use '%%%' for wildcard checking
> so, for anywhere
> SELECT * FROM table WHERE field LIKE '%%%name%%%'
> for right side:
> SELECT * FROM table WHERE field LIKE '%%%name'
> and for left
> SELECT * FROM table WHERE field LIKE 'name%%%'
>
> That is one way to do it.
> -joel
>
> On Tue, 2004-11-16 at 16:08, DeWitt, Michael wrote:
> > Does anyone know if there is a way to write a query in a v3 engine to do
> a
> > query comparing two columns using like?
> >
> > I would like to count all rows where the last name appears in the
> company
> > name.
> >
> > In sql server a query like this works:
> >
> > select count(*) from table where company like rtrim(last_name)+'%'
> >
> > Thanks in advance.
> >
> > Mike
> >
> > _______________________________________________
> > New York PHP Talk
> > Supporting AMP Technology (Apache/MySQL/PHP)
> > http://lists.nyphp.org/mailman/listinfo/talk
> > http://www.newyorkphp.org
> >
> --
> joeldg - developer, Intercosmos media group.
> http://lucifer.intercosmos.net
>
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
More information about the talk
mailing list