简体   繁体   中英

joining 2 columns in 1 table

Im not sure of the right way to do this so help needed if possible please :)

I have a table of football fixtures with the following fields:

id, hteam, ateam, hscore, ascore, date, time

I want to return all the fixtures for one team so where hteam OR ateam = 1 but this doesnt seem to work.

Is there a way I can join or merge these 2 columns to get all the fixture for a particular team?

thanks in advance :)

So to clarify, you have a single table, and you want to return the row if hteam or ateam is 1? If so, something like SELECT * FROM table WHERE hteam=1 OR ateam=1

if u want that if ateam = 1 then show ateam column otherwise hteam column then try

SELECT id, hscore, ascore, date, time,
    IF(ateam=1,atem,hteam) AS fixture ,
FROM  fixtures

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM