I have searched the forums, but I cannot find an answer to the problem I am facing. If I missed a post that has already been solved, please point me in that direction.
I have the following query that takes up to 10 seconds to return results (with only 30,000 records):
Code:
$sql = "SELECT DISTINCT
mls_listings.c1,
mls_listings_images.c1,
mls_listings.c2,
mls_listings.c3,
mls_listings_images.c3 as image,
mls_listings.c4,
mls_listings.c5,
mls_listings.c6,
mls_listings.c7,
mls_listings.c8,
mls_listings.c9
FROM
mls_listings,
mls_listings_images
WHERE
(SELECT DISTINCT mls_listings.c1 = mls_listings_images.c1) AND
(mls_listings_images.c1 LIKE '%{$_GET['uniqueid']}%') AND
(((mls_listings.c3 IN (
'{$_GET['redondobeach']}',
'{$_GET['santamonica']}',
'{$_GET['specificcity']}',
'{$_GET['hermosabeach']}',
'{$_GET['elsegundo']}',
'{$_GET['manhattanbeach']}',
'{$_GET['marinadelrey']}',
'{$_GET['palosverdes']}',
'{$_GET['playadelrey']}',
'{$_GET['playavista']}',
'{$_GET['torrance']}',
'{$_GET['venice']}',
'{$_GET['westchester']}',
'{$_GET['losangeles']}')
) OR
(mls_listings.c7 LIKE '{$_GET['zipwestla']}'))
OR
(mls_listings.c1 LIKE '{$_GET['uniqueid']}')
)
AND
(mls_listings.c5 >= '{$_GET['beds']}') AND
(mls_listings.c6 >= '{$_GET['baths']}') AND
(
mls_listings.c4 >= '{$_GET['minprice']}' AND
mls_listings.c4 <= '{$_GET['maxprice']}'
)
GROUP BY mls_listings_images.c1
ORDER BY mls_listings.c4";
Does anyone have any tips on how I can better optimize this query?
Thank you!