[thelist] Re: SQL gurus

Alex Farran alex at alexfarran.com
Thu Mar 31 14:05:38 CST 2005


Theodore Serbinski writes:

> SELECT m1.date,m1.mileage,m1.notes,m2.date AS \'match\' FROM m m1 LEFT
> JOIN m m2 ON (m1.date=m2.date AND m1.mileage=m2.mileage AND m2.notes
> LIKE \'%'.$searchString.'%\')';

> Seems to work like a charm. Feel free to chime if you have any other
> better solutions. Based on this the "match" field will have the date
> value if a match is found... then in PHP I just test to see if this
> field isn't null...works great!

You can do it without the join like this:

select date, mileage, notes, notes like '%whatever%' as match from m;

Alex
-- 

    __o    Alex Farran - Open source software specialist 
  _`\<,_   PHP | MySQL | E-Commerce | Content Management
 (_)/ (_)  site: www.alexfarran.com  blog: alexfarran.blogspot.com
           phone:01273 474065  mobile:07790 389330


More information about the thelist mailing list