SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

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 September 2nd, 2004, 04:33 PM
Kemetian Kemetian is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 26 Kemetian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 7 sec
Reputation Power: 0
Query based on multiple table searches?

I have a MS Access database with two tables that Im trying to use with each other. The first table is tblContact(fields are: UserID, name, address, email) and the second is tblCategory(fields are: UserID, State, County). What Im trying to do is, based on what was filled out on a form I have(state and county) it will go through tblCategory and search for the state and county and when it finds them it will take the UserIDs then match that UserID or UserIDs(if more than one exist) to the UserID(s) in tblContact and then whatever UserIDs match it will take the email field from tblContact and email the information I want sent to those emails. I already know how to send the email and all that, and I even had the whole thing working with just one table(I just added an email field and threw some email addys in it.). I was just using this:
strSQL = "SELECT DISTINCT email FROM tblCategory WHERE State='" & state &"' AND County='" & county &"'" But how do I do this with two tables? And I dont know a lot about SQL but I know that the ONLY field that these two tables have the same name is UserID, so is it possible to search through tblCategory by state and county and then get the UserIDs then match those to the UserIDs in tblContact and then pull the emails from tblContact that match the UserIDs???? I hope this makes sense.. Thanks for any help. I really appreciate it.

Reply With Quote
  #2  
Old September 2nd, 2004, 04:51 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
Code:
SELECT A.Email
FROM tblContact As A
INNER JOIN tblCategory As B On (A.UserID = B.UserID)
WHERE B.Country = '" & Country & "'
AND B.State = '" & State & "'

Reply With Quote
  #3  
Old September 2nd, 2004, 11:14 PM
Kemetian Kemetian is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 26 Kemetian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 7 sec
Reputation Power: 0
Thats for an MSSQL database? Any idea on how to do this with an MSAccess database? Or would this sql statement work for ms access too?

Thanks

Reply With Quote
  #4  
Old September 3rd, 2004, 09:15 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
try it and see if it works.

Reply With Quote
  #5  
Old September 4th, 2004, 01:59 AM
Kemetian Kemetian is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 26 Kemetian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 7 sec
Reputation Power: 0
Doesnt work. Says:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Type mismatch in expression.




......
Ive gotten this same error using different sql statements as well. Hmm.


Thanks for the help though. Maybe one day I will figure it out, lol, or just quit so I dont have to worry about it anymore.



Thanks again..

Reply With Quote
  #6  
Old September 5th, 2004, 08:03 PM
Kemetian Kemetian is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 26 Kemetian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 7 sec
Reputation Power: 0
Well I figured it out for what I needed to do... Here is the sql query:
strSQL = "SELECT DISTINCT info.email, ContractorCat.UserID FROM info, ContractorCat WHERE ContractorCat.County = '" & county & "' AND ContractorCat.State = '" & state & "' AND ContractorCat.Category = '" & category & "'"

This seems to be working for me.

Thanks for all the help.

Reply With Quote
  #7  
Old September 8th, 2004, 11:44 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
You really should join the tables instead of using Distinct. Bad habit to start

S-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Query based on multiple table searches?


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 4 hosted by Hostway
Stay green...Green IT