select * from fshop_products, music_musician join
fshop_product_cat_mp3 on fshop_products.cat_id=fshop_product_cat_mp3.cat_id
where is_product_sale=1 and fshop_product_cat_mp3.cat_status='Active' and
fshop_products.uploaded_song_userid = music_musician.musician_userid and
music_musician.paid_member = 1 order by rand() limit 0,15";
You are mixing two join methods, which is bad form and can cause poor query planning.
Stick to join syntax (also learn to indent your SQL so it's easier to understand / troubleshoot):
select *
from fshop_products
join music_musician
on (fshop_products.uploaded_song_userid = music_musician.musician_userid)
join fshop_product_cat_mp3
on (fshop_products.cat_id=fshop_product_cat_mp3.cat_id)
where
is_product_sale=1
and fshop_product_cat_mp3.cat_status='Active'
and music_musician.paid_member = 1
order by rand() limit 0,15";
If you have a large data set then order by rand() is going to be slower at a geometric rate, and get super slow once the dataset you're running it on exceeds buffer memory in your db. There's a sticky post in this forum on ways around that, but first, let's get this query working and readable so I'm not squinting when I look at it. 🙂
Note that you should time the speed of this query first:
select count(*)
from fshop_products
join music_musician
on (fshop_products.uploaded_song_userid = music_musician.musician_userid)
join fshop_product_cat_mp3
on (fshop_products.cat_id=fshop_product_cat_mp3.cat_id)
where
is_product_sale=1
and fshop_product_cat_mp3.cat_status='Active'
and music_musician.paid_member = 1 ;
to see how long it's taking to just return the whole set. the order by rand() is going to take a bit more time on its own after that. If the time to retrieve just the count(*) is long, don't expect any miracles using rand() to popup, we'll need to come up with a way to apply one of the methods mentioned in the stick thread to speed things up.