mysql multiple conditions in if statement
mysql
Solution
if you need vl.leagueid and hl.leagueid are equal put the condition on where, like this
`WHERE gamedate between '2013-01-01' AND '2013-12-31' AND vl.leagueid = hl.leagueid`
EDIT If you want to set leaguematch to specific value if the conditions are met, 0 if they are not CASE would be the best option
SELECT visitor AS school,
home AS temp,
vl.leagueid AS vleague,
hl.leagueid AS hleague,
CASE
WHEN school = 50 AND temp = 2 THEN '1'
WHEN school = 51 AND temp = 3 THEN '2'
ELSE 0
END AS leaguematch
FROM ......
I
Problem
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' ```