Skip to main content
Inspiring
June 26, 2006
Answered

cfquery join issue

  • June 26, 2006
  • 2 replies
  • 774 views
i have had an issue where i am trying to join these 3 tables and count the records in the subquery. if anyone can provide some help with this,.... thnx.

SELECT DISTINCT *
FROM ((stSupportTroubleTicket t
LEFT JOIN stEmployee e ON e.Emp_ID = t.UsersID)
LEFT JOIN stTTdiscussion d ON d.ttID = t.ID)
WHERE t.complete = 0 AND t.project = 0
ORDER BY t.ID DESC

i'm trying to COUNT the records in stTTdiscussion.

(this is a support trouble ticket program that has a comment on ticket section. I am making a digg.com type 15 comments interface and i would like to know the number of comments in that one ticket.)

MSAccess db, win2K3, MX 6.1
This topic has been closed for replies.
Correct answer Newsgroup_User
> Adam, the query i have here does work,

Hmmm. Well that's a start. I've emulated your DB locally and it works for
me too. It might have been because I was doing a mix of RIGHT and LEFT
outer joins when I ran into a problem with Access last time.

Anyway, is this what you want:

SELECT t.ID, count(d.ttID) as discussionCount
FROM ((stSupportTroubleTicket t
LEFT JOIN stEmployee e ON e.Emp_ID = t.UsersID)
LEFT JOIN stTTdiscussion d ON d.ttID = t.ID)
WHERE t.complete = 0 AND t.project = 0
GROUP BY t.ID
ORDER BY t.ID DESC

--
Adam

2 replies

June 26, 2006
I dont know if this works in access or not, if you had a real database you could do something like this:

SELECT DISTINCT *
,TTCount = (SELECT COUNT(*) FROM stTTdiscussion d WHERE d.ttID = t.ID)
FROM stSupportTroubleTicket t
LEFT JOIN stEmployee e ON (e.Emp_ID = t.UsersID)
WHERE t.complete = 0 AND t.project = 0
ORDER BY t.ID DESC
elDonricoAuthor
Inspiring
June 26, 2006
ryan, thanks for the reply, but, no, it doesnt work in access.
Inspiring
June 26, 2006
Don't quote me on this, but I don't *think* one can have two outer joins in
one query in Access. You might need to separate your SQL into two separate
queries (where one query queries the second one).

Are you married to Access as part of your solution? It really is a bit
"limited" (politely put). Given the choice I'd use MySQL or MSDE or
something else which actually has a decent feature set and is still free.

--
Adam
elDonricoAuthor
Inspiring
June 26, 2006
Adam, the query i have here does work, its just that i cant get the count of the discussion table. i am not an advocate of access, it is, though, what i have to work with on this project. if i get the time to do a rehaul, i will change the backend, but, that would give me a lot of queries to change...