I am looking for a tip on how to optimize this....
SELECT u.uid,
u.username,
u.nid,
wd.pay
FROM (users_data AS u
LEFT JOIN winners_data wd
ON u.nid = wd.nid
AND u.uid = wd.uid)
LEFT JOIN dp_node dn
ON u.nid = dn.nid
WHERE u.uid = ".$val."
AND ((dn.TYPE = 'event'
AND (SELECT Count(nid)
FROM tournament_event
WHERE nid = u.nid
AND type_value IN ('A','B','C')) > 0)
OR (dn.TYPE = 'new_event'
AND (SELECT Count(nid)
FROM user_tournament_event
WHERE nid = u.nid
AND type_0_value IN ('Y','X')) > 0))
ORDER BY nid ASC
Actually the $val is nothing but the uid that comes from the following query one at a time as a part of my loop.
SELECT DISTINCT(dump.uid) FROM leader_Jdump AS dump
Is there any way to add this part as well to the above query? I guess it will be faster if I can do it at the MySQL level.