I'm trying to write mysql query for advanced search of my website, the website is classified website and I'm trying to filter the ads, I have:
- t_userads
- t_useradsvalues
the useradsvalues contains the userad values which the user choose, useradsvalues table structure:
- ID
- userAdID
- fieldID
- optionID
the fields and options are already defined in another tables.
ex: Need ads for BMW Car has color filed ID is 10 & Green option ID is 33 also doors field ID is 8 ans 4doors option ID is 15
now I tried to write
SELECT
*
FROM `t_userads`
WHERE
(`categoryID` = 53 OR `categoryID` = 54 OR `categoryID` = 141)
AND `countryID` = 8
AND `ad_active` = 1
AND `id` IN (
SELECT
`useradID`
FROM `t_useradsvals`
WHERE (`fieldID` = 10 AND `optionID` = 33) AND `useradID` IN (
SELECT
`useradID`
FROM `t_useradsvals`
WHERE (`fieldID` = 8 AND `optionID` = 15)
)
)
I got the result right but the mysql query took about 6sec to execute (I have 5000 ads) and It's a problem because how it will take if I have 100,000 ads ?
Thank you.