Reputation: 48
I have a question about SQL.
I have two tables.
Buy and Sell
In these tables are somewhat the same data.
ID, quantity, sum, timestamp
How do i print both tables, ordered by the timestamp. So it looks like this
Buy | 1 | 5 | 100 | 14:14:14 |
Buy | 2 | 22 | 50 | 14:14:20 |
Sell | 1 | 1 | 20 | 14:15:01 |
And so on.. I just have to be ordered by the timestamp
Upvotes: 1
Views: 82
Reputation: 154
You should be able to do:
SELECT ID, Quantity, Sum, TimeStamp
FROM Buy
UNION ALL
SELECT ID, Quantity, Sum, TimeStamp
FROM Sell
ORDER BY TimeStamp
Upvotes: 1
Reputation: 3137
Use UNION
SELECT 'Buy' as [Type], b.* FROM BUY as b
UNION ALL
SELECT 'Sell' as [Type], s.* FROM SELL as s
ORDER BY Timestamp
Upvotes: 3