Adding another join to Left Join?

N

Noozer

I have the follow query that returns all the details pertaining to each
ticket, plus how many actions exist for that ticket...

SELECT * FROM Tickets
LEFT JOIN [SELECT TicketKeyLink, COUNT(*) AS ActionCount FROM Actions GROUP
BY Actions.TicketKeyLink]. AS b ON Tickets.TicketKey=b.TicketKeyLink;

....I need to be able to filter the results so that the only tickets that are
returned are the ones that I have actioned (Actions.ActionBy='8213')

So, for the output I want Tickets.*, ActionCount (number), ActionedByMe
(boolean)

I cannot, for the life of me, figure out how to write this query. I think
it's just the way I'm trying to use "EXISTS", but I'm honestly too confused
at this point to know what to do.

I'm guessing that it would be something like...

SELECT * FROM (Tickets
LEFT JOIN [SELECT TicketKeyLink, COUNT(*) AS ActionCount FROM Actions GROUP
BY Actions.TicketKeyLink]. AS b ON Tickets.TicketKey=b.TicketKeyLink)
LEFT JOIN [SELECT TicketKeyLink, EXISTS( SELECT * FROM Actions WHERE
ActionBy='8213' GROUP BY Actions.TicketKeyLink) AS ActionedByMe]. AS c ON
Tickets.TicketKey=c.TicketKeyLink;
 
D

David S via AccessMonster.com

In these sort of situations, I generally think it's a good idea to use
multiple queries rather than try to get the one query to do everything - that
way, your first query could limit the Actions to just the ones you're
interested in, and then you could use that query in your LEFT JOIN.

It would help if you could post the tables and the field names as well -
otherwise, we have to try and figure them out from the queries you've posted,
which is a lot more work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top