New to mysql, so I am not sure I am even asking the question correctly. I am trying to add multiple parameters to an if statement. I am trying to check if a game between two teams was a league match.
SELECT visitor AS school, home AS temp, vl.leagueid AS vleague, hl.leagueid AS hleague,
if(vl.leagueid = hl.leagueid, 1, 0) AS leaguematch
FROM schedule
LEFT JOIN schools AS vl ON vl.id = visitor
LEFT JOIN schools AS hl ON hl.id = home
WHERE gamedate between '2013-01-01' AND '2013-12-31'
To the check if leagueid's are equal I want to add ((vl.leagueid = 26 AND hl.leagueid = 27) OR (vl.leagueid = 27 AND hl.leagueid = 26)). No combinations of () that I have tried seems to work, so I get the feeling I am going about this wrong.
Thanks, Mike
Thanks to chofer, here is my working query
SELECT visitor AS school, home AS temp, vl.leagueid AS vleague, hl.leagueid AS hleague,
CASE
WHEN vl.leagueid = hl.leagueid THEN '1'
WHEN ((vl.leagueid = 26 AND hl.leagueid = 27) OR (vl.leagueid = 27 AND hl.leagueid = 26)) THEN '1'
ELSE 0
END AS leaguematch
FROM u96nk_rvball_schedule
LEFT JOIN u96nk_rvball_schools AS vl ON vl.id = visitor
LEFT JOIN u96nk_rvball_schools AS hl ON hl.id = home
WHERE gamedate between '2013-01-01' AND '2013-12-31'