Merging results from 3 different queries
- November 18, 2009
- 3 replies
- 830 views
Hello people, I was wondering if someone could help me with this.
I have a search by keyword feature that will bring results from 3 different tables in the following way:
We have the following tables:
- Prop (prop description, image location and propID basically)
- PropCat (catID, catName)
- PropSub (subID, subName and catID)
- propHist (each prop can be in many categories/subcategories. table structure: histID, propID, catID, subID)
When someone types a keyword to search for props, this is what happens (see attached jpg for a screen capture):
Results by prop name:
I have 1 query that searches the keyword in the prop name.
"Props found where keyword found in prop name."
(all the props here)
Results by Category name:
I have 1 query that searches the keyword in the category name and returns the IDs
A loop thru the propHist (another query) searching all the propIDs found in the catID from the above query.
Once the query retrieves the propID, another query to get me the propName, location and image associated to it.
Display results.
I close the loop.
Results by SubCategory name:
I have 1 query that searches the keyword in the subcategory name and returns the IDs.
A loop thru the propHist (another query) searching all the propIDs found in the subID from the above query.
Once the query retrieves the propID, another query to get me the propName, location and image associated to it.
Display results.
I close the loop.
Now, I know it's not the correct way but I'm getting the results I need when I do the search. One problem is that results may repeat since the keyword may be found in the prop name and the category name as well.
I would love to bring a consolidate result set.
So instead of separating by prop name, category name and subcategory name, just a simple result with all the results retrieved above, but avoiding repetitions.
Too confusing?
Any help will be welcome.
-------------------------------
Dani Szwarc
Thiez Multimedia
dani@thiez.com
