Counting Rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven

    Counting Rows

    Hi there,

    I have an admin system (Add/Modify/Delete) for two types of records in the
    database. They have a Parent - Child relationship

    My problem is that I want to display on the "parent" record whether the
    child exists or not .

    The records are found in two different tables, but have the same Primary
    Key.

    Any ideas

    cheers

    Steven


  • Chris Hope

    #2
    Re: Counting Rows

    Steven wrote:
    [color=blue]
    > I have an admin system (Add/Modify/Delete) for two types of records in the
    > database. They have a Parent - Child relationship
    >
    > My problem is that I want to display on the "parent" record whether the
    > child exists or not .
    >
    > The records are found in two different tables, but have the same Primary
    > Key.[/color]

    You'll be wanting to use a LEFT JOIN then. With a left join you can show all
    the results from the first table whether or not there is a related record
    from the second/joined table. The columns that would have been displayed
    from the second table will all be NULL.

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Paul Robson

      #3
      Re: Counting Rows

      Steven wrote:
      [color=blue]
      > Hi there,
      >
      > I have an admin system (Add/Modify/Delete) for two types of records in the
      > database. They have a Parent - Child relationship
      >
      > My problem is that I want to display on the "parent" record whether the
      > child exists or not .
      >[/color]

      Left Join. If you select [stuff] from table 1 left join table 2 on [stuff]
      then every record in table 1 will appear ; if there aren't child record(s)
      in table 2 for table 1 then the corresponding field will be null.
      [color=blue]
      > The records are found in two different tables, but have the same Primary
      > Key.[/color]

      I don't think you mean this :) they'll have different primary keys but a
      foreign key in the child .


      Comment

      • Tony Marston

        #4
        Re: Counting Rows


        "Paul Robson" <autismuk@autis muk.muralichuck s.freeserve.co. uk> wrote in
        message news:cktatu$3qb $2@newsg3.svr.p ol.co.uk...[color=blue]
        > Steven wrote:
        >[color=green]
        >> Hi there,
        >>
        >> I have an admin system (Add/Modify/Delete) for two types of records in
        >> the
        >> database. They have a Parent - Child relationship
        >>
        >> My problem is that I want to display on the "parent" record whether the
        >> child exists or not .
        >>[/color]
        >
        > Left Join. If you select [stuff] from table 1 left join table 2 on [stuff]
        > then every record in table 1 will appear ; if there aren't child record(s)
        > in table 2 for table 1 then the corresponding field will be null.
        >[color=green]
        >> The records are found in two different tables, but have the same Primary
        >> Key.[/color]
        >
        > I don't think you mean this :) they'll have different primary keys but a
        > foreign key in the child .
        >[/color]

        It is possible for the primary key on the child table to be exactly the same
        as the foreign key which links to the parent table. This is the way to
        enforce a one-to-one relationship. If the child table has a different
        primary key it will allow a one-to-many relationship which may not be
        desirable.

        --
        Tony Marston

        This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




        Comment

        Working...