PDA

View Full Version : subquery, union? no idea what I need


fruitwerks
10-28-2009, 12:46 AM
This will be rather simple for the more seasoned persons here, but I have never had to do anything like this so far...

SELECT
pnl.pnl_desc,
pnl.pnl_value,
pnl.id_pnl
FROM
pnl
WHERE
(pnl.pnl_cust = whatever_id_I_need)

this gives me some raw details but for each match on the above, I need some more details

WHERE pnl_trans = pnl.id_pnl [
COUNT notes.note
COUNT pnl_items.items
SUM pnl_items.value
SUM payments.value
]

the above mentioned tables all have the pnl_trans (PK from pnl) and cust_id (pnl_cust)

no idea what method would be best, or exactly how to structure it

Thanks!

Old Pedant
10-28-2009, 07:49 AM
Ummm...you don't show at all how the four tables are related.

That is, what links pnl to all the other tables???

Without that info, we can't even guess at an answer.

technica
10-28-2009, 08:36 AM
If I am not wrong then subqueries take more execution time than union.


The relationship between the tables is required to know here, to think for the best solution over the problem.

You can post the structure of the tables and the information which is required to etch from these tables.