![]() |
searching with LIKE - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: searching with LIKE (/showthread.php?tid=34175) |
searching with LIKE - El Forum - 09-21-2010 [eluser]Peter Dräxler[/eluser] Hi guys. PHP: Code: function like_find($keywords, $limit = 0, $offset = 0) SQL: Quote:SELECT `products`.*, `suppliers`.`Name` AS Supplier FROM (`products`, `suppliers`) WHERE `products`.`Supplier` = suppliers.Id AND `products`.`Code` LIKE '%text%' OR `products`.`PartNo` LIKE '%text%' OR `products`.`EAN` LIKE '%text%' OR `products`.`Name` LIKE '%text%' OR `products`.`Manufacturer` LIKE '%text%' ORDER BY `products`.`Price` ASC I want 1 line of every suitable product but it get 9 lines of every product :-( Please help! Thank's searching with LIKE - El Forum - 09-21-2010 [eluser]bretticus[/eluser] You need a GROUP BY clause. searching with LIKE - El Forum - 09-21-2010 [eluser]jmadsen[/eluser] I think a DISTINCT might work better for him. GROUP BY is typically used when you want to use aggregates. It's not a correct way of eliminating duplicates, unless your query forces you into it for some reason. searching with LIKE - El Forum - 09-21-2010 [eluser]bretticus[/eluser] True. I suppose it depends on how the tables are structured ultimately. Since we don't know... searching with LIKE - El Forum - 09-22-2010 [eluser]Peter Dräxler[/eluser] Thank's for reply. Table products with sample data: http://dl.dropbox.com/u/1645785/products-table.png Table suppliers with actually data: http://dl.dropbox.com/u/1645785/suppliers-table.png I think, GROUP BY or DISTINC don't help me. I can have 2 records which will have different just Supplier and I want to view both. |