tags:

views:

81

answers:

3

I have a table with the following columns:

 id, teamA_id, teamB_id

Will it be possible to write a SELECT statement that gives both teamA_id and teamB_id in the same column?

EDIT:

Consider this example

From

 id, teamA_id, teamB_id
 1, 21, 45
 2, 34, 67

I need

Teams
21
45
34
67
A: 

Try this

SELECT teamA_id || ' ' || teamB_id
Evan Carroll
+5  A: 

There are a few ways to do this, here is one method:

SELECT team_id
FROM
  (SELECT teamB_id AS team_id FROM my_table)
  UNION ALL
  (SELECT teamA_id AS team_id FROM my_table)

(This solution also happens to satisfy the clarification in your edit.)

Dolph
hahah, this would be the same column but two different rows. I up-voted because the (badly) worded question led me off to make a different assumption.
Evan Carroll
Same mistake here...
gbn
A: 

Look at the SQL Concatenate function:

http://www.1keydata.com/sql/sql-concatenate.html

Each database provides a way to do this:

* MySQL: CONCAT()
* Oracle: CONCAT(), ||
* SQL Server: +
Nate