Victor,

Thank you for the information, that was helpful.

At least part of the problem is the variables you are replacing in that string, 
which we can't see.

The statement should be something like:

select * from ben_franklin_planners c join products p on c.Item=p.Item join 
categories cat on p.Category=cat.ID

Make your code produce the above, and you should be fine.  I suspect you don't 
need LEFT JOIN there, an inner join will suffice.

For more info on joins:
http://hashmysql.org/index.php?title=Introduction_to_Joins
For more indepth info: 
http://dev.mysql.com/tech-resources/articles/mysql-db-design-ch5.pdf
http://dev.mysql.com/doc/refman/5.1/en/join.html

Regards,
Gavin Towey

From: Victor Subervi [mailto:victorsube...@gmail.com]
Sent: Thursday, October 01, 2009 2:25 PM
To: Gavin Towey; mysql@lists.mysql.com
Subject: Re: Nested Joins

On Thu, Oct 1, 2009 at 4:03 PM, Gavin Towey 
<gto...@ffn.com<mailto:gto...@ffn.com>> wrote:
Joins aren't nested like that, unless you use a subquery.  I think you just 
need to remove the parens around the second join.

I tried that and no go :(

For better help:
1. show the real SQL -- echo the statement.  Most people here don't like 
looking at app code because your variables could contain anything.
ProgrammingError: (1064, "You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right syntax to 
use near ') left join categories on products.Category=categories.ID)' at line 
1"), referer: http://13gems.com/global_solutions/spreadsheet_edit.py
2. Give the exact error message
Isn't that the same thing?

3. If there's no error, explain what you expect and what you're getting

4. Include table schema
DESCRIBE `ben_franklin_planners`
ID      int(4) unsigned      NULL
Item     int(4) unsigned     NULL
Discount     int(2) unsigned     NULL

DESCRIBE categories
ID      int(3)      primary key not NULL      auto_increment
Category     varchar(20)     unique NULL

describe products
ID      int(4)      primary key not NULL
Category     int(3)     NULL
Item     varchar(20)     UNIQUE     NULL
Description     varchar(255)     NULL
UOM     varchar(20)     NULL
Price     float(7,2)     NULL


5. Explain what you're trying to accomplish.
  cursor.execute('select * from %s left join products on %s.Item=products.Item 
left join categories on products.Category=categories.ID;' % (client, client))

The "client" in this case is ben_franklin_planners
ben_franklin_planners has an item # that is the same as the item # in products, 
where all the information about the products is to be found, EXCEPT the name of 
the category. For that, we have to go to the categories table.

Hope that makes it clear.
TIA,
V


________________________________
The information contained in this transmission may contain privileged and 
confidential information. It is intended only for the use of the person(s) 
named above. If you are not the intended recipient, you are hereby notified 
that any review, dissemination, distribution or duplication of this 
communication is strictly prohibited. If you are not the intended recipient, 
please contact the sender by reply email and destroy all copies of the original 
message.

Reply via email to