Reputation: 299
How to move the data from different rows with same ID in same rows but different column? For example, I have this table
tblEx
--------------
|ID|Buy |Sell|
|--+----+----|
|1 |10 | |
|1 | |11 |
|2 |20 | |
|2 | |0 |
|3 |0 | |
|3 | |30 |
--------------
Desired Output:
--------------
|ID|Buy |Sell|
|--+----+----|
|1 |10 |11 |
|2 |20 |0 |
|3 |0 |30 |
--------------
Upvotes: 0
Views: 119
Reputation: 263763
Based from the given example and desired result, you can use MAX()
SELECT ID, MAX(Buy) AS Buy, MAX(Sell) AS Sell
FROM TableName
GROUP BY ID
Upvotes: 3