Lyleyboy Posted July 17, 2007 Share Posted July 17, 2007 Hi all, I am doing a league table script for a project but I cant make it do one thing I would really like. I hope there is a way. If have two team names coming in from a form. $team1 & $team2. Basically these are entered by the users by way of saying "I want to see the fully history of these two teams" But my table has two fields home_team & away_team My query at the moment is $sql="SELECT * FROM user WHERE home_team='$team1' and away_team='$team2'"; This is fine but it only returns half the records I want. What I need is to say $sql="SELECT * FROM user WHERE home_team='$team1' OR '$team2" and away_team='$team2' OR '$team1""; I hope that made sense. Please give me a shout Quote Link to comment Share on other sites More sharing options...
Illusion Posted July 17, 2007 Share Posted July 17, 2007 SELECT * FROM user WHERE home_team='$team1' OR '$team2' UNION SELECT * FROM user WHERE away_team='$team1' OR '$team2' Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted July 17, 2007 Author Share Posted July 17, 2007 Cool, I will give that a whirl. Does the UNION act as an "and" the or just join two queries? Quote Link to comment Share on other sites More sharing options...
Illusion Posted July 17, 2007 Share Posted July 17, 2007 just combines and display the records returned from the second query to the first one records. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.