Re: Multi Table Query Help
From: Pedro Graca (hexkid_at_dodgeit.com)
Date: 12/20/04
- Next message: Janwillem Borleffs: "Re: post variables always undefined"
- Previous message: badr: "Re: Leech (?) content of mySQL tables"
- In reply to: Steve: "Multi Table Query Help"
- Next in thread: Steve Edwards: "Re: Multi Table Query Help"
- Reply: Steve Edwards: "Re: Multi Table Query Help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Dec 2004 12:17:02 GMT
Steve wrote:
> The two tables are product and vendor. A vendor can be a manufacturer,
> distributor, or both. This is indicated via the manufacturer_YN and
> distributor_YN fields in the vendor table, and vendor_id is an
> auto_number field. In the product table, there is a manufacturer_id and
> a distributor_id field, and these are linked to the vendor.vendor_id
> field.
>
> What I would like to do is for each product, display the name, short
> description (both fields in product table), manufacturer, and
> distributor. The problem I'm having is writing a query to get all this
> info at once so it can be displayed.
Please post your tables definition (use the output of the DESCRIBE
command).
Just guessing I'd think something like this works:
SELECT p.name,
p.short_description,
v1.name as manufacturer,
v2.name as distributor
FROM product p,
vendor v1,
vendor v2
WHERE p.manufacturer_id=v1.id
AND p.distributor_id=v2.id
AND v1.manufacturer_YN='yes'
AND v2.distributor_YN='yes'
I guess (I'm pretty sure) the JOIN syntax would be better, but I never
liked that syntax and can't write a JOIN query without a lot of editing
out errors before it works the way I want :-)
-- Mail to my "From:" address is readable by all at http://www.dodgeit.com/ == ** ## !! ------------------------------------------------ !! ## ** == TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>) may bypass my spam filter. If it does, I may reply from another address!
- Next message: Janwillem Borleffs: "Re: post variables always undefined"
- Previous message: badr: "Re: Leech (?) content of mySQL tables"
- In reply to: Steve: "Multi Table Query Help"
- Next in thread: Steve Edwards: "Re: Multi Table Query Help"
- Reply: Steve Edwards: "Re: Multi Table Query Help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|