...

View Full Version : Query from a query results



Bengal313
11-21-2003, 08:47 PM
Okay let me try to explain. I have these 2 tables.

Table: DOG_HEADER
owner
house_no
street_name
apt_no
phone


Table: DOG_DETAIL
license
expire_year
no_year
dog_name
dog_breed
House_no
street_name
apt_no

One to many relation: For one DOG_HEADER many DOG_DETAILS


I have a search form that take in the values for license, expire_year, and no_year and displays the results from the DOG_DETAL table. Now on that same page I want to diplay info about the do's owner from the DOG_HEADER table. The two tables are links via house_no, street_name, and apt_no. so when you do the original search using license, expire_year, no_years the results do contain house_no, street_name, apt_no. So without having to have another detail page how can I use the result info to query the other table and display it on the same page.

missing-score
11-21-2003, 10:15 PM
i think i get what you mean, but i dont quite get the relation between the tables.

try this:

SELECT dd.*, dh.owner, dh.phone
FROM DOG_DETAIL as dd
RIGHT JOIN DOG_HEADER as dh
ON (dh.apt_no = dd.apt_no)

Bengal313
11-21-2003, 11:12 PM
So, this should query the dog_header table using the results from the search_page and display the results of the search page and the second query on the same page.

Well the relationship that. The DOG_HEADER table has the owners information and the Dog_Detail contain the dog information. so 1 owner can have many dogs. The House_no, street_name, and apt_no make up the primary key (unique) in the table DOG_HEADER.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum