Jump to content

Three AND statements


Mr Chris

Recommended Posts

Hi Guys,

 

I have a query, but it has three AND statements:

 


SELECT r.match_date, th. team_name  AS home_team, ta. team_name AS away_team, r.team_one_score, r.team_two_score, r.competition, r.fixture_id, r.team_one_id, r.team_two_id
FROM results r
INNER JOIN teams th ON r.team_one_id = th.team_id
INNER JOIN teams ta ON r.team_two_id = ta.team_id
WHERE r.match_date > CURDATE()
AND r.team_one_score='' 
AND r.team_two_score=''
AND th.team_id='1' OR ta.team_id='1' 
ORDER BY match_date ASC
LIMIT 1

 

Now if I get rid of the AND statements the first part of the query works.  Is there a better way I can use my AND statements to get this query to work?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/61865-three-and-statements/
Share on other sites

try using parenthasis

 

SELECT r.match_date, th. team_name  AS home_team, ta. team_name AS away_team, r.team_one_score, r.team_two_score, r.competition, r.fixture_id, r.team_one_id, r.team_two_id
FROM results r
INNER JOIN teams th ON r.team_one_id = th.team_id
INNER JOIN teams ta ON r.team_two_id = ta.team_id
WHERE r.match_date > CURDATE()
AND r.team_one_score='' AND r.team_two_score=''
AND (th.team_id='1' OR ta.team_id='1')
ORDER BY match_date ASC
LIMIT 1

Link to comment
https://forums.phpfreaks.com/topic/61865-three-and-statements/#findComment-308209
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.