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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.