0

with this sample dataset

enter image description here

I have this query

SELECT products.id, 
                        products.title AS product_title, 
                        products.code, 
                        products.created, 
                        products.modified,
                        products.active,
                        attributes.title AS attr_title,
                        attribute_entries.title AS attr_entry_title
                        FROM products 
                        INNER JOIN attributes ON attributes.model_id = products.id 
                        INNER JOIN attribute_entries ON attribute_entries.FK_attribute_id = attributes.id WHERE ( products.id LIKE '%" . $model['value'] . "%' OR products.code LIKE '%" . $model['value'] . "%' OR products.title LIKE '%" . $model['value'] . "%') limit 10

For some reason I get duplicates in my result set. I have done this type of query before but I never got duplicates. Although this is the first time I query the id as well and treat it as string. Is this my problem?

enter image description here

1
  • Congratulations on resolving your own problem - please don't forget to mark it as correct (no points though :-) ). In future, could you please refrain from posting screenshots for the reasons listed here. p.s. welcome to the forum!
    – Vérace
    Mar 17, 2019 at 16:05

1 Answer 1

0

I just added GROP BY products.id and it is fine now. dumb, dumb.

IF this isn't proper or a better solution please feel free to post.

SELECT products.id, 
                    products.title AS product_title, 
                    products.code, 
                    products.created, 
                    products.modified,
                    products.active,
                    attributes.title AS attr_title,
                    attribute_entries.title AS attr_entry_title
                    FROM products 
                    INNER JOIN attributes ON attributes.model_id = products.id 
                    INNER JOIN attribute_entries ON attribute_entries.FK_attribute_id = attributes.id WHERE ( products.id LIKE '%" . $model['value'] . "%' OR products.code LIKE '%" . $model['value'] . "%' OR products.title LIKE '%" . $model['value'] . "%') GROUP BY products.id limit 10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.