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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query question 1

Status
Not open for further replies.

MikeNL

Programmer
Feb 6, 2006
8
NL
Hi,

I have a little issue creating a query, I have the following setup:

tbl_Page:
-PageID
-PageTitle
-PageInsertUserIDFK
-PageEditUserIDFK

tbl_User:
-UserID
-UserName

I want to join those tables and display the username who created the page and the username of the user who has been editing the page. Can someone give me some help setting this query up?? I'm using Access btw, I should use MySQL or MSSQL, but the client wants Access :(

Hope someone can help!

My blog:
 
Something like
Code:
SELECT InsertUser.PageID, InsertUser.PageTitle, InsertUser.UserName as InsertUser, EditUser.UserName as EditUser
FROM (SELECT tbl_User.UserName, tbl_Page.PageID, tbl_Page.PageTitle
FROM tbl_User RIGHT JOIN tbl_Page ON tbl_User.UserID = tbl_Page.PageEditUserIDFK) As EditUser 
INNER JOIN (SELECT tbl_User.UserName, tbl_Page.PageID, tbl_Page.PageTitle
FROM tbl_User INNER JOIN tbl_Page ON tbl_User.UserID = tbl_Page.PageInsertUserIDFK) As InsertUser 
ON EditUser.PageID = InsertUser.PageID;
?

Hope this helps
 
Sorry about asking again, but what if I also want to include the pageActiveUserIDFK and the pageDeleteUserIDFK??

I tried to modify it, but I think I'm using the wrong syntax for it....

If anyone could show me how to add some more JOIN stuff for this, that would be great!

Thanks in advance!

My blog:
 
Actually, you can play arround with single queries to get one value for each specific user from tbl_user, then create another query based on those queries, in this case 4 queries.

Code:
SELECT tbl_Page.PageID, tbl_Page.PageTitle, InsertUser.UserName, EditUser.UserName, ActiveUser.UserName, DeleteUser.UserName
FROM DeleteUser 
INNER JOIN (ActiveUser 
     INNER JOIN (EditUser 
          INNER JOIN (InsertUser 
               INNER JOIN tbl_Page 
               ON InsertUser.PageID = tbl_Page.PageID) 
          ON EditUser.PageID = tbl_Page.PageID) 
     ON ActiveUser.PageID = tbl_Page.PageID) 
ON DeleteUser.PageID = tbl_Page.PageID;

Please note that unnecessary fields have been removed from the selection.

Hope this helps,
mansii
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top