I have two tables:
tbl_profiles_and_users:
[id] [int] IDENTITY(1,1) NOT NULL,
[profile_id] [int] NOT NULL,
[user_id] [nvarchar](50) NULL
tbl_profiles_and_activities:
[id] [int] IDENTITY(1,1) NOT NULL,
[profile_id] [int] NOT NULL,
[user_id] [nvarchar](50) NOT NULL,
[activity_name] [nvarchar](50) NULL,
[check] [int] NULL,
[preferred] [int] NULL
both tables have entries in them, and I am trying to select the user, and activities, only from within a specified profile.
I am trying to do this with the following join:
use [dbName]
SELECT p1.user_id AS User_ID, [p2.activity_name] as [Activity_Name]
FROM tbl_profiles_and_users AS p1
INNER JOIN tbl_profiles_and_activities AS p2
ON p1.user_id = p2.user_id AND p1.profile_id = p2.profile_id
but I receive the message Invalid column name 'p2.activity_name' What am I doing wrong? Can I achieve the desired results with a Join?