php-windows Digest 10 Jan 2005 16:15:21 -0000 Issue 2529
Topics (messages 25277 through 25277):
SQL syntax question
25277 by: Anne Shroeder
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Not sure if this is the right list to post this to or not -- I'm having a
problem with getting a MySQL query to work. I need to do two things:
(1) multiply the value of x*y (and thus have to do a group by) from fields
in one table, AND
(2) do a lookup of the name value in another table for a foreign key from
the first table.
E.g.
select sum (qty1*unitprice1), field1, field2
from table1
group by field1, field2
That part works fine, but when I try to mix in the second table, it breaks:
select sum (table1.qty1*table1.unitprice1), table1.field1, table1.field2,
table2.name
from table1, table2
where table1.nameid = table2.id
group by table1.field1, table1.field2, table2.name
Clearly, you can't group by a foreign table - but then how to do the join
to get the name definition from table2?
Anne
--- End Message ---