[Zope-DB] mySQL query question

Ed Leafe ed@leafe.com
Wed, 22 Jan 2003 17:39:42 -0500


On Wednesday, January 22, 2003, at 05:07  PM, Maszerowski, Thomas wrote:

>   I'm using a mySQL database (that I did not set up). It's a list of 
> items
> each of which is owned by a name. Rather than have the name in the 
> table as
> a string, the owner is actually an index into another, separate table, 
> that
> contains the text string of the name. For adding records, I figured 
> out how
> to use a SQL method and then a <dtml-in> to build the HTML <select> so 
> the
> user doesn't see anything but the text. However, when I do a listing 
> of the
> database, I would like to also to display the text of the name, rather 
> than
> the index. How can I do this? I would essentially like to only call 
> the SQL
> method for the names once, and reference the text associated with the 
> owner
> index for each line in the listing. Any help, or pointers to 
> information
> would be most appreciated.

	Assuming that you have two tables named Items and Owners, and that the 
Items table has a foreign key to its Owner named OwnerID, your SQL 
statement should look like:

SELECT Owners.Name, Items.*
FROM Items LEFT JOIN Owners
    ON Items.OwnerID = Owners.OwnerID
WHERE ... etc.

> Tom Maszerowski
> Xerox Innovation Group/Xerox Engineering Center
> MS: 105-70C
> Phone (585) 422-1579
> Fax (585) 422-2837
> TMaszerowski@crt.xerox.com

	Hey, I live in Penfield. Are you working at the Webster facility?


      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com