On 6/21/07, Guillermo <[EMAIL PROTECTED]> wrote:
Hello,
    I have a query that i could do in 2 diferent ways...i want to know wich one 
is recomended:

  *  Select T1.field1,T1.field2, (select sum(T2.field4) from Table2 T2 where 
T2.field1 = T1.field1) from Table1 T1

     or

  *  Select P1.field1,P1.field2,P2.field2 from (Select T1.field1,T2.field2 from 
T1) as P1 left join (Select sum(T2.field4) from Table2) as P2 on P1.field1 = 
P2.field1

If you're looking for speed, I would avoid the subqueries:

SELECT T1.field1,T1.field2, SUM(T2.field4)
FROM    Table1 T1
JOIN     Table2 T2 ON (T1.field1 = T2.field1)
GROUP BY 1, 2

- Perrin

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to