Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Joins on three tables Expand / Collapse
Author
Message
Posted Monday, February 25, 2013 3:46 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 25, 2013 10:44 PM
Points: 3, Visits: 10
I have three tables namely,

TBL_SRTAPPGROUPPOWER ,
TBL_SRTTICKETMASTER and
TBL_MARVEL_STATUS which has status id 1to25

I wrote the following query to fetch the count of tickets with status id ( MSTAT_N_SID ) but i'm unable to get the status ids with count 0 (zero)
How can i get it ? Please help

select MSTAT_N_SID, count(TSTM.TICKET_N_TICKETNO) from TBL_MARVEL_STATUS TSM left join TBL_SRTTICKETMASTER TSTM on TSM.MSTAT_N_SID=TSTM.TICKET_N_STATUSID WHERE TICKET_N_APPID IN (SELECT AG_N_APPID FROM TBL_SRTAPPGROUPPOWER WHERE AG_V_APPGROUPID='1') GROUP BY MSTAT_N_SID;

The Output:
MSTAT_N_SID COUNT(TSTM.TICKET_N_TICKETNO)
---------------------- -----------------------------
1 11
4 1
7 2
9 2
11 80
15 2
Post #1423528
Posted Monday, February 25, 2013 7:44 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:05 PM
Points: 13,327, Visits: 12,820
Hi an welcome to the forums. It is impossible to answer your question with the limited amount of details you posted. Please take a few minutes to read the article in my signature about best practices when posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1423612
Posted Monday, February 25, 2013 9:09 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, September 18, 2014 1:52 PM
Points: 504, Visits: 1,870
I agree with Sean. Please see the link he has referenced. We'll be able to give you better help with more complete information.

In the meantime, take a look at the WHERE clause in the query. It appears that you may have put WHERE conditions on the TBL_SRTTICKETMASTER table. If that's the case, it would prevent the LEFT JOIN from allowing the null conditions to be returned. Those would be the rows that you'll need to get your zero counts. Not sure if this is the issue but it's something you might want to investigate.

Here's an article that discusses the impact of WHERE clause filters on LEFT JOINS.
Post #1423652
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse