Having trouble getting my SQL statement right.
Have a products page and filters down the left hand side. Currently it works if 2 filters is selected on the left then it either of those filters are matched then the product is displayed.
I want it to be that if both filters are matched then the product is displayed.
Main Product Table
![Main Product Table]()
Main Filters table
![Main Filter Table]()
Currently MY SQL Statement is (which shows product if either filter mathed) and works:
Select DISTINCT Main.ID, Main.* From Main INNER JOIN MainFilters ON Main.Id = MainFilters.MainId WHERE Available=1 AND (CategoryIds = '3' OR CategoryIds LIKE '3,%' OR CategoryIds LIKE '%, 3,%' OR CategoryIds LIKE '%, 3') AND (((FilterId=4) AND ( FilterValues = '9' OR FilterValues Like '%9,%' OR FilterValues Like '%, 9')) OR ((FilterId=9) AND ( FilterValues = '43' OR FilterValues Like '%43,%' OR FilterValues Like '%, 43'))) Order By DisOrder, Main.ID Desc, Title
But I am having trouble to get both match.
Tried this SQL but it doesn't work.
Select DISTINCT Main.ID, Main.* From Main INNER JOIN MainFilters ON Main.Id = MainFilters.MainId WHERE Available=1 AND (CategoryIds = '3' OR CategoryIds LIKE '3,%' OR CategoryIds LIKE '%, 3,%' OR CategoryIds LIKE '%, 3') AND (((FilterId=4) AND ( FilterValues = '9' OR FilterValues Like '%9,%' OR FilterValues Like '%, 9')) AND ((FilterId=9) AND ( FilterValues = '43' OR FilterValues Like '%43,%' OR FilterValues Like '%, 43'))) Order By DisOrder, Main.ID Desc, Title
How should I build my SQL Statement?