Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

== Trouble writing a query == 1

Status
Not open for further replies.

Lynux

MIS
Aug 3, 2001
33
US
I have a table of "activities" and a table of "user_activities".... once a user completes an activity in the "activities" table and logs that in on our web site it shows up as a completed task... here is the query that is used:
==========================>

Select fname, lname, user_activities.activities_ID, activities.description
from users, user_activities, activities where users.pin = 5099 AND user_activities.PIN = 5099 AND
user_activities.activities_ID = activities.ID

====================================================
The big question is... How do I query the table "activities" using the table "user_activities" to show all of the activities that the user has not completed yet? I tried the obviouse Query:
=======================>

Select fname, lname, user_activities.activities_ID, activities.description
from users, user_activities, activities where users.pin = 5099 AND user_activities.PIN = 5099 AND
user_activities.activities_ID <> activities.ID

======================================================

That was the furthest thing from the output I was looking for........... Anyone have any suggestions?
If you can answer this one you got my vote! :)

Thanks a ton in advance! =================================
Imagination is more important than knowledge.
(A.E.)
 
This query may or may not work in your RDMS. It uses the LEFT JOIN to select All Activities showing the user's name when user has completed an activity and NULL when the user has not completed the actvity

Select
a.ID,
a.description,
u.fname,
u.lname

From activities As a
Left Join (user_activities As ua
Inner Join users As u
On ua.PIN=u.PIN)
On a.ID=ua.activities_ID
Where u.pin = 5099

If you want the user's name to appear on every line in the result set, you'll need to modify the query. The nature of these modifications will depend on your RDMS. Terry L. Broadbent
Programming and Computing Resources
 
Thanks amillion Terry ! =================================
Imagination is more important than knowledge.
(A.E.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top