TSQL joins

I'm trying to setup this query so that all records form the Registration table show and when G.MYID does not = R.MYID, then the value would be a zero.  


SELECT        COUNT(G.GuestRegID) AS GCOUNT, R.MYID
FROM            dbo.Guest AS G Full OUTER JOIN
                         dbo.Registration AS R ON G.MYID= R.MYID
WHERE        (G.IsActive = 1)
GROUP BY G.MYID, R.MYID

How could I modify this query to show all records in R, and if G.MYID does not equal R.MYID then return a zero?

I'm using SQL Server 2012.
Thanks.
javierpdxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sameer2010Commented:
Hi, if you want to show all records in R and just show 0 as the count for rows that do not have G row, you can do the following
SELECT        R.MYID, isnull(g.myid,0) growexsists
FROM            dbo.Registration AS R left outer join dbo.Guest AS G ON G.MYID= R.MYID
WHERE        (G.IsActive = 1)

Open in new window

0
PortletPaulfreelancerCommented:
I think it is this:
SELECT
        R.MYID
      , ISNULL(COUNT(G.MYID),0) AS GCOUNT
FROM dbo.Registration AS R
LEFT OUTER JOIN dbo.Guest AS G
        ON G.MYID = R.MYID
        AND (G.IsActive = 1)
GROUP BY R.MYID

Open in new window

a where condition to G would cause the effect of an inner join so it needs to be a join condition instead.

{+edit} sorry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
javierpdxAuthor Commented:
Thanks.  I was struggling with this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.