![]() | |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
here is a short description of the schema : |
|
- I've orders with an amount |
|
- An order can be associated with several deliveries, each one having also an amount (a delivery has a FK referencing the order). |
|
I would like to produce following result that joins both tables without repeating order amounts : Order A $100 Develiery1 $50 Develiery2 $30 Develiery3 $20 Order B $200 Develiery4 $200 Order C $120 Develiery5 $70 Develiery6 $50 |
#3
| |||
| |||
|
|
pif_orders=> SELECT DISTINCT order_code, order_amount, delivery_sequence, delivery_amount FROM ( SELECT code AS order_code, amount AS order_amount FROM stock_order ) AS o NATURAL JOIN ( SELECT order_code, sequence AS delivery_sequence, amount AS delivery_amount FROM stock_delivery ) AS d ORDER BY order_code, delivery_sequence; |

#4
| |||
| |||
|
|
And even if the "blank" stuff should be in there I don't understand the complicated sub-query you were using ![]() |
#5
| |||
| |||
|
|
Thomas Kellerer <OTPXDAJCSJVU (AT) spammotel (DOT) com> writes: And even if the "blank" stuff should be in there I don't understand the complicated sub-query you were using ![]() For didactic purposes. I prefer to have attribute names that make sense in the context of the relation; and then use attribute renames in the select so that a natural join will just work. |

|
Join conditions give me hives; every join should be natural anyway :-) |
#6
| |||
| |||
|
|
Thomas Kellerer <OTPXDAJCSJVU (AT) spammotel (DOT) com> writes: And even if the "blank" stuff should be in there I don't understand the complicated sub-query you were using ![]() For didactic purposes. I prefer to have attribute names that make sense in the context of the relation; and then use attribute renames in the select so that a natural join will just work. Join conditions give me hives; every join should be natural anyway :-) |
#7
| |||
| |||
|
|
Ben Finney wrote on 28.11.2009 01:36: Thomas Kellerer <OTPXDAJCSJVU (AT) spammotel (DOT) com> writes: And even if the "blank" stuff should be in there I don't understand the complicated sub-query you were using ![]() For didactic purposes. I prefer to have attribute names that make sense in the context of the relation; and then use attribute renames in the select so that a natural join will just work. I agree ![]() Join conditions give me hives; every join should be natural anyway :-) Hmm, natural joins give _me_ the creeps. They are not relying on FK relations |
|
but on naming conventions. |
#8
| |||
| |||
|
|
Ben Finney <bignose+hates-spam (AT) benfinney (DOT) id.au> writes: I prefer to have attribute names that make sense in the context of the relation; and then use attribute renames in the select so that a natural join will just work. Join conditions give me hives; every join should be natural anyway :-) Hmm. Interesting assertion. Why avoid things like outer joins? |
|
I've recently been working on improving the performance of an application and by far, the most beneficial performance gains I've made has been from replacing really inefficient sub-queiries with a much simpler and more efficient outer join. |
|
However, I find it odd that people will use a more complex and usually inefficient sub-query rather than a simpler join. Am I missing something here? |
#9
| |||
| |||
|
|
Hello, here is a short description of the schema : - I've orders with an amount - An order can be associated with several deliveries, each one having also an amount (a delivery has a FK referencing the order). I would like to produce following result that joins both tables without repeating order amounts : |
|
Order A $100 Develiery1 $50 Develiery2 $30 Develiery3 $20 Order B $200 Develiery4 $200 Order C $120 Develiery5 $70 Develiery6 $50 .... I would like to find a select request without using PL/SQL procedure if it is possible. |
#10
| |||
| |||
|
|
and then use a function or user application to process the relation into whatever output text you like for the report. Turning relations into reports isn't the job of the DBMS. |
![]() |
| Thread Tools | |
| Display Modes | |
| |