0

i am just begin learning mysql for php! i have a problem with query mysql to get data team from table i have a table with the fields table name (team)

id, OPPONENT, COMPETITION

data table (team) like this

**id**  **OPPONENT**    **COMPETITION**
     1      barcelona         real madrid 
     2      barcelona         Villarreal   
     3      real madrid       ruby

i want write query to get table like this

 **team**
 barcelona
 Villarreal
 real madrid 
 ruby   

2 Answers 2

1

This table should have foreign key of your teams and you would simply select teams name in teams table.

Anyway, if you want to do it that way, try this:

SELECT DISTINCT opponent AS team FROM table
UNION
SELECT DISTINCT competition AS team FROM table
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT DISTINCT t.opponent team FROM (
    SELECT opponent team
    FROM tbl
    UNIOUN ALL
    SELECT competition team
    FROM tbl
) t

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.