You are here: unusual behaiour with MySQL LIKE and LEFT join « PHP Programming Language « IT news, forums, messages
unusual behaiour with MySQL LIKE and LEFT join

Posted by D_a_n_i_e_l on 08/21/07 14:30

I have a form which has a field for filtering a query, the code behine
the form uses the LIKE clause. When I enter "a%" in the field the form
returns all records starting with "a" (as expected.) But when I enter
"e%" no rows are displayed even though there is one record on my
database starting with "e". when. An SQL count with the same clauses
returns 1 record (as expected.) I isloated the discrepancy to two SQL
calls:

SELECT COUNT(*) FROM `testtbl` as a LEFT JOIN `testreftbl2` AS b ON
a.`testref2`=b.`id`,`testreftbl1` AS c WHERE a.`testtext` LIKE "e%"
AND a.`testdbl` LIKE "%" AND a.`testref1`=c.`id`;

no. of records=1

SELECT
a.`testid`,a.`testtext`,a.`testdbl`,a.`testopt`,a.`testradio`,b.`disp`,c.`disp`,a.`testchk`
FROM `testtbl` as a LEFT JOIN `testreftbl2` AS b ON
a.`testref2`=b.`id`,`testreftbl1` AS c WHERE a.`testtext` LIKE "e%"
AND a.`testdbl` LIKE "%" AND a.`testref1`=c.`id` ORDER BY a.testtext
ASC,a.testdbl ASC LIMIT 1,10;

no. of records=0

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация