Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 7th, 2004, 04:57 PM
jrickards jrickards is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 17 jrickards User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Searching across records

I am stumped with a particular problem - wonder if anyone has any ideas.

Consider this table of tblPubAuthors

PubID, txtAuthors
001, Tom
001, Jerry
002, Tom
003, Jerry
004, Bob
005, Tom
005, Jerry
005, Bob
006, Bob
006, Jerry

If I search for "Tom OR Jerry" I will get PubID 001, 002, 003, 005 and 006. If I search on "Tom AND Jerry", I will get zero results because no txtAuthors field contains both Tom and Jerry such as:

PubID, txtAuthors
001, Tom Jerry
005, Tom Jerry Bob

so, I don't know how to find just 001 and 005 which are the only publications for which txtAuthor lists both Tom and Jerry (I don't care if there are other authors, the minimum would be Tom AND Jerry).

Here's a thought:

Set recset = db.recordset("Select PubID, txtAuthor from tblPubAuthors where txtAuthors = 'Tom' or txtAuthors = 'Jerry'")

which will result in:

PubID, txtAuthors
001, Tom
001, Jerry
002, Tom
003, Jerry
005, Tom
005, Jerry
006, Jerry

then:

Set recset2 = db.recordset("Select PubID from recset Where count(PubID) > 1 Group on PubID")

(pardon the syntax if I have made a mistake but I hope you see where I am headed)

Might this work? If I have the count() function correct, since count of 002, 003 and 006 are 1 which is not >1, then recset2.PubID will contain 001 and 005.

Any takers? If this seems to be able to work, is there anyway I could combine the two selects?

TIA,

Reply With Quote
  #2  
Old February 8th, 2004, 11:06 AM
jrickards jrickards is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 17 jrickards User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Solved the problem

OK got it now and it is a very elegant solution. I need it to work in Access 97 at work and because I have Access 2000 at home, I will have to wait until tomorrow to test it.

The SQL is:

SELECT PubID
FROM tblPubAuthors
WHERE txtAuthors = 'Tom' OR txtAuthors = 'Jerry'
GROUP BY PubID
HAVING Count(PubID) >= 2

I will modify this code to use "LCase(txtAuthors) Like '*tom*'" in place of "txtAuthors = 'Tom'" to allow for some mispellings but the basics are there and within one SQL query, all the work is done.

Hope this helps someone else as much as it helps me,

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Searching across records


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway