got stuck with a query

wxdqz

New Member
Ok..I am puzzling on this one for a while now and I can't see it...some help would be nice :)

Here is the problem:

I have got 3 tables A, B and C

A:
key_ID
key

B:
key_ID
document_ID
count

C:
document_ID
title
attributes


Now I enter a key in a form and this goes to a php page which processes the key (so far so good)

First I all de documents with that key
that works.
All documents have a number of keys, from the first part several documents are selected with the initial key. Now I want to show the 20 most common keys within all the selected documents.

Example:

the documents are:
doc1 = bli bli bla
doc2 = blo blu bli bla
doc3 = bla blo

database would be:
A:
key_ID key

1 bli
2 bla
3 blo
4 blu

B:
key_ID document_ID count

1 1 2
2 1 1
3 2 1
4 2 1
1 2 1
2 2 1
2 3 1
3 3 1

C:
document_ID title attributes

1 doc1 123(whatever)
2 doc2 41545352
3 doc3 95761576y-5721-

Now we fill out the form and seek 'bli'.

The result of documents should be:
doc 1
doc 2
this way because the count of bli in doc 1 is higher.

Now the big problem (yeah a lot of explaining I know)
I want to show all the remaining keys of doc 1 and doc 2 (because they are in the result)

should be (top 20 keys):
bla (count = 2)
blo (count = 1)
blu (count = 1)

this is a very simplistic example and you have to see this in a bigger database with larger document etc...

HOW ?????????


Many thx for tha one who helps me with this one...
 
Back
Top