February 14, 2008 at 3:30 am
Hi!
I can't seem to find a way to "join" two tables in one result set. It's kind of difficult to explain this, but I will try...
I've got two tables, "orders" and "ordersAbroad". They have got the same columns and I want to join them as "one table". The problem is the articles have got diffrent articleID depending on if it is a domestic or foreign order. Let's say all domestic articles has got ID less than 1000 and foregn above and I want the result set to look like this:
[font="Courier New"]
orderDate articleID quantity
2008-01-01 102 10
2008-01-01 161 12
2008-01-01 1008 9
2008-01-01 1063 13
[/font]
Has anyone got a solution?
Thanks!
/Martin
February 14, 2008 at 4:03 am
Martin Larsson (2/14/2008)
Hi!I can't seem to find a way to "join" two tables in one result set. It's kind of difficult to explain this, but I will try...
I've got two tables, "orders" and "ordersAbroad". They have got the same columns and I want to join them as "one table". The problem is the articles have got diffrent articleID depending on if it is a domestic or foreign order. Let's say all domestic articles has got ID less than 1000 and foregn above and I want the result set to look like this:
[font="Courier New"]
orderDate articleID quantity
2008-01-01 102 10
2008-01-01 161 12
2008-01-01 1008 9
2008-01-01 1063 13
[/font]
Has anyone got a solution?
Thanks!
/Martin
Hi Martin,
Would a union be sufficient?
SELECT orderDate
, articleID
, quantity
FROM orders
UNION ALL
SELECT orderDate
, articleID
, quantity
FROM ordersAbroad
ORDER BY orderDate
This will return you the data from both tables. If not, maybe you could describe in a bit more detail what is stored in your tables, and what is the expected result.
Regards,
Andras
February 14, 2008 at 5:51 am
Many thanks! Problem solved...
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply