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!

== Trying to query a table against another? == 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.)
 
A suggestion:
Code:
SELECT DISTINCT
users.fname
,users.lname
,user_activities.activities_ID
,IF(isnull(user_activities.activities_ID),Null,activities.description) AS description
FROM activities
LEFT JOIN user_activities ON CONCAT(activities.ID,5099)=CONCAT(user_activities.activities_ID,users_activities.PIN)
LEFT JOIN users ON user_activities.PIN=users.PIN

Post your output and the structure of your tables if it doesn't work!

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top