Hello Cesar--

Your database design is not normalized, so you're going to have to cheat
a bit--try this (I'm doing it from memory, so it might not work on the
first try):

select distinct Relationships.Subcatid, Subcategories.* from
Relationships Inner Join Subcategories On Catid = '0001' and
Relationships.Subcatid = Subcategories.subcatid

Assuming that it works, this is highly inefficient, because the
Relationships table should really be split in two or three different
tables, so that you would really only manipulate the minimum set of data
needed to achieve your goals.

Also, please don't cross-post. It clutters the mailing lists and it's
bad form.


php|architect - The Magazine for PHP Professionals
The monthly magazine dedicated to the world of PHP programming

Check us out on the web at http://www.phparch.com!
--- Begin Message ---
Hi all,

I have several tables from which I have to fetch certain products &
categories based on customer selection. The tables are as follows:

Table 1 - Categories
catid (autonum)

Table 2 - Sub categories
subcatid (autonum)

Table 3 - Products
prodid (autonum)

Table 4 - Relationships

Now, the question is how to fetch all the sub-categories let's say that
are related to category 0001. I know it's as simple as relating two
tables in one query, but I don't remember how. Any help appreciated.

Cesar L. Aracena
(0299) 156-356688
Neuquén (8300) Capital

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to