Optimize query syntax
I have a pair of users, and I want to find is the relationship between users allready exists, so I wrote this query, that I dont like.IT checks if
(partner1=user1 AND partner2=user2) OR (partner2=user1 AND partner1=user2)
SELECT n.nid FROM node n INNER JOINcompetition_pair p ON p.nid = n.nid INNER JOIN content_type_competition_pair c ON c.nid = n.nid WHERE n.type='competition_pair' AND ((c.competition_partner1_uid=%d AND c.competition_partner2_uid=%d) OR (c.competition_partner1_uid=%d AND c.competition_partner2_uid=%d)) AND p.active=1
How can I make this more simple?
could you please do a SHOW CREATE TABLE for your three tables, and explain each one, what it's for
from node n
join competition_pair p
on p.nid = n.nid
join content_type_competition_pair c
on c.nid = n.nid
where n.type = 'competition_pair'
and (%d,%d) in ((c.competition_partner1_uid,c.competition_partner2_uid),
and p.active = 1
Thank you, It looks better than my code.