mysql - SQL query not returning expected results -


here's sql query scrubbed (just column/table/database names). kept structure same production. query taken mysql log.

select      master.pk pk,             master.vendor_id vendorid,             master.vendor_text vendorname,             master.device_id deviceid,             master.device_did devicedid,             master.device_text devicename,             master.class_id classid,             master.class_text classname,             master.oem_id oemid,             master.oem_did oemdid,             master.oem_text oemname,             master.oem_vendor_text oemvendor,             master.comment comment,             master.v1 v1,             master.v2 v2,             master.status status,             dev_mod_join.mod_text module        master left join   dev_mod_join         on   master.device_did = dev_mod_join.dev_id (              master.device_text concat("%", 'search term', "%")        or   master.vendor_text concat("%", 'search term', "%")        or   master.oem_text concat("%", 'search term', "%")        or   master.oem_vendor_text concat("%", 'search term', "%")        ) group    master.vendor_text limit     0, 25 

for reason, returning 1 result per vendor. odd. there can several devices per vendor. if search vendor know has lot of devices, still return 1 device vendor (it returns other devices have other vendors, else matches search term, gives 1 per vendor).

anything i'm missing, think has "or"s, know, shouldn't case.

help appreciated, always.

edit: omg, may have figured out. used group instead of order by.

wow, been looking @ while , 5 minutes on , it

the query appears sound part, part looks suspicious group by. try distinct in select clause instead of group by.

like this:

select distinct                   master.pk pk,             master.vendor_id vendorid,             master.vendor_text vendorname,             master.device_id deviceid,             master.device_did devicedid,             master.device_text devicename,             master.class_id classid,             master.class_text classname,             master.oem_id oemid,             master.oem_did oemdid,             master.oem_text oemname,             master.oem_vendor_text oemvendor,             master.comment comment,             master.v1 v1,             master.v2 v2,             master.status status,             dev_mod_join.mod_text module        master left join   dev_mod_join         on   master.device_did = dev_mod_join.dev_id (              master.device_text concat("%", 'search term', "%")        or   master.vendor_text concat("%", 'search term', "%")        or   master.oem_text concat("%", 'search term', "%")        or   master.oem_vendor_text concat("%", 'search term', "%")        ) 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -