Jump to content

query to display identical data from two columns in one table?


gerryf19

Recommended Posts

I have a table of a sports schedule like this called SCHEDULE

 

Home, Away,Location,Date,Time

team1, team2,field1,June 9, 9am

 

team3, team4,field2,June 9, 9am

team2, team4,field2,June 19, 9am

 

team3, team1,field1,June 19, 9am

 

...
 
I want to extract just the schedule for team1, both home and away with the following
 
SELECT *  FROM `SCHEDULE` WHERE `Home`='team1' AND Away='team1'
 
the only result I get is

Home, Away,Location,Date,Time

team1, team2,field1,June 9, 9am

 

Shouldn't I be getting

 

Home, Away,Location,Date,Time

team1, team2,field1,June 9, 9am

team3, team1,field1,June 19, 9am
 

with this query?

 

 

 

 

Link to comment
Share on other sites

No, you shouldn't even be getting ANY result with that query because none of the records have Team1 as the Home team AND the Away team. That would only occur if Team1 was playing themselves! So, I am confused as to why you are even getting a result. There must be some other problem causing that. You should be using an OR condition.

Edited by Psycho
Link to comment
Share on other sites

Thanks Psycho, I actually had OR in there, not AND....just typed it wrong. As I stated above, the problem was that the AWAY field was imported from a CSV file and everything in it is preceded by a space, i.e., " Team1", " Team2" etc.....That's why I was tearing my hair out, OR  should have worked, but I had bad data....

Link to comment
Share on other sites

OK, well, if you haven't already figured out how you are going to solve this, I would suggest the following:

 

1. Update the import process to trim the values before inserting into the database.

2. Run a query to correct all the current values

 

UPDATE `SCHEDULE`
SET `Home` = TRIM(`Home`),
    `Away` = TRIM(`Away`)
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.