John, I am stumped (which seems to becoming a normal state). So I joined www.experts-exchange.com and posted the question. I think it was you who recommended that site. Anyway, I'll let you know what happens.
Thanks, Mark -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Stanley Sent: Thursday, July 28, 2005 2:22 PM To: '[email protected]' Subject: RE: [plum] Custom Query for Two Plum Users Mark, sorry about the missing plus signs, that was a syntax error on my part. have you tried this? (keep in mind that I know jack squat about access except that it is finiky): you should still be able to use table aliases (although I could be wrong there). there were also spaces in front of PU and NewMessage that I removed, but i dont know if that matters. SELECT NewMessage.NewMessageId, NewMessage.NewMessageText, PU2.FirstName + ' ' + PU2.LastName as 'messageFrom', PU.FirstName + ' ' + PU.LastName as 'messagesentTo', NewMessage.MessageDate, NewMessage.MessageStatus FROM NewMessage INNER JOIN PlumUser PU on ([PU].[UserID] =[NewMessage].[MessageSentTo]) INNER JOIN PlumUser PU2 on ([PU2].[UserID] = [NewMessage].[MessageFrom]) -----Original Message----- From: Mark Fuqua [mailto:[EMAIL PROTECTED] Sent: Thursday, July 28, 2005 2:12 PM To: [email protected] Subject: RE: [plum] Custom Query for Two Plum Users Hey John, It sure looks like it will work, however I can't seem to get it to. I am using Access2000 which has some peculiarities. The first items it didn't like were the lack of + signs between the '' and LastName Fields. Fixed that. Then it was the JOIN. Seems Access likes INNERJOIN. After studying what you wrote and looking at the lame Access help, this is where I am: SELECT NewMessage.NewMessageId, NewMessage.NewMessageText, PU2.FirstName + ' ' + PU2.LastName as 'messageFrom', PU.FirstName + ' ' + PU.LastName as 'messagesentTo', NewMessage.MessageDate, NewMessage.MessageStatus FROM NewMessage INNER JOIN PlumUser PU on([ PU].[UserID] =[ NewMessage].[MessageSentTo]) AND PlumUser PU2 on ([PU2].[UserID] = [NewMessage].[MessageFrom]); The error message I have now is "syntax error in join statement" and it highlights the PU inside the brackets. Is it possible to just remove the PU and PU2? Or is it necessary for the SELECT to know which "firstName" goes with which field? Thanks John, below I copied the section in the Access help for inner join. INNER JOIN Operation Combines records from two tables whenever there are matching values in a common field. Syntax FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field2 The INNER JOIN operation has these parts: Part Description table1, table2 The names of the tables from which records are combined. field1, field2 The names of the fields that are joined. If they are not numeric, the fields must be of the same data type and contain the same kind of data, but they do not have to have the same name. compopr Any relational comparison operator: "=," "<," ">," "<=," ">=," or "<>." Remarks You can use an INNER JOIN operation in any FROM clause. This is the most common type of join. Inner joins combine records from two tables whenever there are matching values in a field common to both tables. You can use INNER JOIN with the Departments and Employees tables to select all the employees in each department. In contrast, to select all departments (even if some have no employees assigned to them) or all employees (even if some are not assigned to a department), you can use a LEFT JOIN or RIGHT JOIN operation to create an outer join. If you try to join fields containing Memo or OLE Object data, an error occurs. You can join any two numeric fields of like types. For example, you can join on AutoNumber and Long fields because they are like types. However, you cannot join Single and Double types of fields. The following example shows how you could join the Categories and Products tables on the CategoryID field: SELECT CategoryName, ProductName FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID; In the preceding example, CategoryID is the joined field, but it is not included in the query output because it is not included in the SELECT statement. To include the joined field, include the field name in the SELECT statement - in this case, Categories.CategoryID. You can also link several ON clauses in a JOIN statement, using the following syntax: SELECT fields FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field1 AND ON table1.field2 compopr table2.field2) OR ON table1.field3 compopr table2.field3)]; You can also nest JOIN statements using the following syntax: SELECT fields FROM table1 INNER JOIN (table2 INNER JOIN [( ]table3 [INNER JOIN [( ]tablex [INNER JOIN ...)] ON table3.field3 compopr tablex.fieldx)] ON table2.field2 compopr table3.field3) ON table1.field1 compopr table2.field2; A LEFT JOIN or a RIGHT JOIN may be nested inside an INNER JOIN, but an INNER JOIN may not be nested inside a LEFT JOIN or a RIGHT JOIN. See Also FROM Clause (Microsoft Jet SQL) TRANSFORM Statement (Microsoft Jet SQL) LEFT JOIN, RIGHT JOIN Operations (Microsoft Jet SQL) UNION Operation (Microsoft Jet SQL) SELECT Statement (Microsoft Jet SQL) Example INNER JOIN Operation Example -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Stanley Sent: Thursday, July 28, 2005 12:45 PM To: '[email protected]' Subject: RE: [plum] Custom Query for Two Plum Users How does this work? SELECT NewMessage.NewMessageId, NewMessage.NewMessageText, PU2.FirstName + ' ' PU2.LastName as 'messageFrom', PU.FirstName + ' ' PU.LastName as 'messagesentTo', NewMessage.MessageDate, NewMessage.MessageStatus FROM NewMessage join PlumUser PU on PU.UserID = NewMessage.MessageSentTo join PlumUser PU2 on PU2.UserID = NewMessage.MessageFrom -----Original Message----- From: Mark Fuqua [mailto:[EMAIL PROTECTED] Sent: Thursday, July 28, 2005 12:36 PM To: [email protected] Subject: [plum] Custom Query for Two Plum Users Good afternoon, I have a table called NewMessages which has two references to the Plum Users table. I have been trying to write a query (at this point anyway) to just return what is in the NewMessage table. What follows doen't work. Any idea what will? SELECT NewMessage.NewMessageId, NewMessage.NewMessageText, NewMessage.MessageFrom, NewMessage.MessageSentTo, NewMessage.MessageDate, NewMessage.MessageStatus FROM PlumUser AS PlumUser1, PlumUser INNER JOIN NewMessage ON (PlumUser.UserID = NewMessage.MessageSentTo) AND (PlumUser.UserID = NewMessage.MessageFrom); Actually, I would like to have the FirstName and LastName AS Name for both references as well. But thought I should try and get it to work with just ID first. But since I am obviously stumped with the easy one and have to ask anyway, I thought... "why not go for all the marbles?" Thanks, Mark ********************************************************************** You can subscribe to and unsubscribe from lists, and you can change your subscriptions between normal and digest modes here: http://www.productivityenhancement.com/support/DiscussionListsForm.cfm ********************************************************************** ********************************************************************** You can subscribe to and unsubscribe from lists, and you can change your subscriptions between normal and digest modes here: http://www.productivityenhancement.com/support/DiscussionListsForm.cfm ********************************************************************** ********************************************************************** You can subscribe to and unsubscribe from lists, and you can change your subscriptions between normal and digest modes here: http://www.productivityenhancement.com/support/DiscussionListsForm.cfm ********************************************************************** ********************************************************************** You can subscribe to and unsubscribe from lists, and you can change your subscriptions between normal and digest modes here: http://www.productivityenhancement.com/support/DiscussionListsForm.cfm ********************************************************************** ********************************************************************** You can subscribe to and unsubscribe from lists, and you can change your subscriptions between normal and digest modes here: http://www.productivityenhancement.com/support/DiscussionListsForm.cfm **********************************************************************
