i have a issue on sql server 2008, i have 2 tables SlideShow and Slide. common field in both the table is SlideShowId.
now to get all the SlideShow with SlideCount i use this procedure.
ALTER PROCEDURE [dbo].[sp_GetAllSlideShow]
@FILTER BIT,
@PORTALID INT
AS
BEGIN
IF (@FILTER = 1)
SELECT SS.SLIDESHOWNAME + ' [' + CAST((COUNT(S.SLIDEID)) AS VARCHAR(MAX))+']', SS.SLIDESHOWID FROM SLIDESHOW SS
INNER JOIN SLIDES S
ON SS.SLIDESHOWID = S.SLIDESHOWID
WHERE SS.PORTALID = 0 AND [TYPE] IS NULL
GROUP BY SS.SLIDESHOWNAME, SS.SLIDESHOWID
ELSE
SELECT SS.SLIDESHOWNAME + ' [' + CAST((COUNT(S.SLIDEID)) AS VARCHAR(MAX))+']', SS.SLIDESHOWID FROM SLIDESHOW SS
INNER JOIN SLIDES S
ON SS.SLIDESHOWID = S.SLIDESHOWID
WHERE SS.PORTALID = @PORTALID
GROUP BY SS.SLIDESHOWNAME, SS.SLIDESHOWID
END
this runs fine, but say if new slideshow has been created, this procedure does not show up that slideshow until new slide has been created in that slideshow, actually that is because i have joined both the tables for SlideCount, and there is no slide for particular slideshow, that slideshow wont show up, but i also want that slideshow. the count in that should be 0 by default.
is there any way i can do that.
That is because you are using an
INNER JOIN. AnINNER JOINwill only show results that are equal in both tables, so if your slideshow record was added to only one table then theINNER JOINwould not pull it in theSELECT. Try changing yourINNER JOINto aLEFT JOIN.