RIGHT JOIN Doesn't Show all Parent Records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harapan
    New Member
    • Nov 2011
    • 1

    RIGHT JOIN Doesn't Show all Parent Records

    Dear expert,

    I'm trying to join two table between master and child table. I want to show all aircraft registration for specified aircraft type even if there is no flight record at the time specified.

    Code:
    SELECT TYPE,
    SREG,
    Sum(FLT_MINUTES)/60/7 AS [AVG FH],
    Sum(FLT_MINUTES) AS FM,
    Count(FLT_MINUTES) AS CYCLE
    FROM AC RIGHT JOIN WEEKLY ON AC.SREG = WEEKLY.AC_REG
    WHERE DEP_UTC BETWEEN #10/31/2011# AND #11/6/2011# AND TYPE = "A330-200"
    GROUP BY TYPE, SREG;
    Unfortunately, from my query result, I cannot see aircraft registration "GPN" (which is an A330-200 and exist but not flight at the time specified). please see attachment.

    Please help.
    [imgnothumb]http://bytes.com/attachments/attachment/5699d1322102225/query-result.jpg[/imgnothumb]
    Attached Files
    Last edited by NeoPa; Nov 24 '11, 03:59 AM. Reason: add explanation GP is an A330-200 - NeoPa made pic viewable
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Originally posted by Harapan
    Harapan:
    I want to show all aircraft registration for specified aircraft type even if there is no flight record at the time specified.
    That begs the question :
    Why include that in the WHERE clause then?

    It's hard to imagine you wouldn't realise that specifying a range in the WHERE clause excludes all records which don't conform to that specification.

    If you want master records with no child records, then you have to handle the possibility of Nulls in [DEP_UTC] (which I'm having to guess is from [AC]), but be careful as this will still exclude master records if there are child records, but none is in the specified period.

    Comment

    Working...