7

I don't have any idea to create this sorry if it is a silly question.

I have a table two teams and total watch and I will use this information later a different place so my idea concat this two column in one column but two different rows:

HomeTeam      AwayTeam     Totalwatch 
A              B              100
A              C               90
C              A               80
D              B               70
C              E               50

Can I this

Teams          TotalWatch
A                100
B                100
A                 90
C                 90
C                 80
A                 80
D                 70
B                 70
C                 50
E                 50

I have a few columns so they will repeat as well.

Just a note I know how can concat in one-row use with concat function I do not know how can I make with two rows

3 Answers 3

9

You can use UNION ALL and an ORDER BY Totalwatch DESC to get the results ordered according to Totalwatch.

SELECT HomeTeam AS Teams, Totalwatch  FROM YourTable
UNION ALL
SELECT AwayTeam, Totalwatch FROM YourTable
ORDER BY Totalwatch DESC;
0
4

Simply use UNION ALL:

SELECT * 
FROM(
    SELECT HomeTeam Teams,TotalWatch FROM Your_Table
    UNION ALL
    SELECT AwayTeam,TotalWatch FROM Your_Table
    )D
ORDER BY TotalWatch DESC
0
2

Try this bro.. :)

SELECT HomeTeam,Totalwatch
FROM   YourTable

UNION ALL

SELECT AwayTeam,Totalwatch
FROM   YourTable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.