I’m trying to pull data out of an Access DB and I’m stumped on how to write the Select Statement. I’ve got two tables, tblLogins and tblPages. tblLogins has these fields; SessionID, User, LoginDate, LoginTime. tblPages has these fields; SessionID, PageID, PageDate, PageTime. The two tables are connected by the SessionID fields using a one-to-many relationship (one record in tblLogins and multiple in tblPages). I want to pull the last 5 distinct pages that a User has visited recently. The only other criteria I have is that I’m excluding certain pages from the list. I’ve got a working Select Statement, but it pulls the Page names in alpha order instead of Date order and the Order By clause doesn’t work with Distinct. Please let me know if you have a solution to this problem, thanks.
Current Select Statement:
strSelect = “SELECT DISTINCT TOP 5 P.PageID FROM tblLogins L, tblPages P
WHERE L.User = ‘UserName’ AND L.SessionID = P.SessionID AND
P.PageID NOT IN(‘Estimate Request DU’, ‘Log Out’, ‘Login DU’, ‘Main Menu’)”
Help @nbcrockett spread the word by sharing this article on Twitter...Tweet This