Updates: It seems that solution did not fix the issue so I am trying to explain in a better way.
I am trying to implement a filter on products display, which has many custom fields and values.
E.g.
Color: Red, Blue, Green
Material: Silver, Gold, Platinum
Manufacturer: MF1, MF2, MF3
Now if someone wants to select all products with Color as Red & Blue, Material as Gold and Manufacturer as MF1, what would be the correct SQL. Please see the DB schema at Fiddle at http://www.sqlfiddle.com/#!2/6373d/2/0
I am using this query as suggested but it is not showing the correct results:
SELECT d1.productid, d1.fieldid, d1.value FROM `xcart_extra_field_values` d1 LEFT JOIN xcart_products_categories AS cat ON d1.productid = cat.productid WHERE (d1.fieldid= '36' AND d1.value LIKE '%14 karat guld%') AND cat.categoryid = '797' UNION ALL SELECT d2.productid, d2.fieldid, d2.value FROM `xcart_extra_field_values` d2 LEFT JOIN xcart_products_categories AS cat ON d2.productid = cat.productid WHERE (d2.fieldid= '37' AND d2.value LIKE '%Brillanter%') AND cat.categoryid = '797'
You did not show what the desired result of your query is but, from what I can tell your query is working but you are only showing the values that are from your table
tbl_fld_valwith the aliasd1. If you change your query slightly, you will see that the records are present:See SQL Fiddle with Demo
If you want the data in to appear in the same columns, then you can use a
UNION ALLsimilar to this:See SQL Fiddle with Demo
Or you can try an
ORbetween yourWHEREclauses:See SQL Fiddle with Demo