I have the following SQL-Select (SQLite/MySQL):
SELECT products.* FROM products
INNER JOIN specifications AS spec1 ON specifications.product_id = product.id
INNER JOIN specifications AS spec2 ON specifications.product_id = product.id
WHERE products.language = "de"
AND products.category = "ABC"
AND (spec1.name = 'Innenabmessungen' AND spec1.value = '182x53')
AND (spec2.name = 'Farbe' AND spec2.value = 'schwarz')
Is there a solution to use only one INNER JOIN? The problem is that I want to make SELECTs with more than two spec-filter. Is this possible?
If you want to return values from both records in the specifications table then it cannot be simplified, since two lookups are required on the specifications table
However in your example you could rewrite it as follows:
Though I don’t think there would be a gain in performance, unless you first did a lookup on the specifications table to find the rows with a matching product_id, and then looked for the names/values
Obviously you would need to index the product_id, name and value fields in the specifications table, as well as the productid, language and category fields in the products table.