Query shows duplicate results

B

B-SQL

Hi, I am a novice with Access, so there might be an easier
way other than SQL.

I created the tables as you indicated a solution would be
to include a DISTINCT in your selection and to NOT
DISPLAY your keywords in the results. If you can live
without showing the results of the key word search, you
should be able run it quickly in this manner and it will
eliminate duplicates while allowing multiple books with
the same keywords.

SELECT distinct(tblLibData.title) AS title,
tblLibData.author, tblLibData.subject
FROM tblLibData INNER JOIN tblKeyData ON
tblLibData.IndexID = tblKeyData.indexID
WHERE (((tblKeyData.keyword) Like ("*" & [Enter Key Word]
& "*")));
-----Original Message-----
I am making a table for a library database, and I have
information such as Title, Author, Subject and Location in
one table called tblLibData. Each record in this table is
given an autonumber called IndexID. I have another table
that is joined to the first table (called tblKeyData) that
contains an IndexID field linked to the first tables'
IndexID field, and a Keyword field so that each book
(IndexID) has a set of keywords associated with it. What
I'm trying to do is make a query that get's an inputed
keyword from a form, searches tblKeyData for a keyword
(basically the form input + a wildcard, so that it
searches for anything starting with what the user inputs)
and outputs the results. The problem I'm having is that
when someone inputs a word, it will sometimes output the
book record more than once.
Here is a sample set of records from tblKeyData to illustrate my problem:

IndexID Keyword
6 roller bearings
6 roller followers
6 rollers
8 roller bearings
8 hand tools

So if I were to input the word "roller" into the form's
input, it would return the Title, Subject, Category, and
Location from tblLibData more than once. I want it to just
show a record once, even though it may find the
word "roller" in 3 keywords of the same record.
I actually fixed this problem by creating a Find
Duplicates query for tblKeyData and copying and pasting
the following code from the Keyword criteria for the Find
Duplicates query into my search query under the Keyword
criteria:
In (SELECT [Keywords] FROM [tblKeyData] As Tmp GROUP BY [Keywords] HAVING Count(*)>1 )

The only problem is that when I actually perform the
search from the form, it runs VERY slowly and takes a long
time to load.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top