I Can't Do This

C

Cine

Hello,

Im new to queries and i'm trying to pull off a seemingly tricky one.

Somehow I need to 'merge' or 'combine' the two queries below into one:

Code:
SELECT        TopicName, Duration
FROM            tblTopics
WHERE        (TopicCode IN (@TopicCode1, @TopicCode2))

Code:
SELECT        DateStarted, DateToEnd
FROM            tblSubscriptions
WHERE        (UserID = @UserID) AND (TopicCode IN (@TopicCode1, @TopicCode2))

At first glance I thought this was impossible to do but it's worth a try
posting on a forum where people know alot more than me on the subject :)

Any ideas?
 
V

vanderghast

Code:
SELECT t.TopicName, t.Duration, s.DateStarted, s.DateToEnd
FROM tblTopics AS t INNER JOIN tblSubscriptions AS s
ON t.topicCode = s.topicCode
WHERE t.topicCode IN( @topicCode1, @topicCode2)
AND s.UserID = @userID

should do, assuming that topicCode is unique in either tblTopics, either in
tblSubscriptions. If it is not unique in BOTH tables, say it appears twice
in each table, then you will get four records, in the result, one for each
possible (here unrestricted) match.


Vanderghast, Access MVP
 

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