Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server Express
»
Joins on three tables
Joins on three tables
Rate Topic
Display Mode
Topic Options
Author
Message
karthik_ayyagari
karthik_ayyagari
Posted Monday, February 25, 2013 3:46 AM
Forum 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
Sean Lange
Sean Lange
Posted Monday, February 25, 2013 7:44 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 3:32 PM
Points: 8,980,
Visits: 8,540
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
Post #1423612
kl25
kl25
Posted Monday, February 25, 2013 9:09 AM
SSC Veteran
Group: General Forum Members
Last Login: Today @ 2:10 PM
Points: 262,
Visits: 1,167
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.