Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2015
    Posts
    7

    Unanswered: Need help with a (phpMyAdmin) SQL exercise

    There is a table called "parents" with attributes: parentID, parentName

    There is also a table called "children" with attributes: childID, childName, parentID

    I need to know the SQL to show names of all parents who have more than one child, together with the number of children that they have.

    The best I can come up with is this but I get errors.

    Code:
    SELECT parentName, count(*)
    FROM parents
    JOIN children ON parentName
    GROUP BY parentName
    HAVING COUNT (childID.parents) >= 1

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What errors?

    Your SQL is malformed.
    Code:
    SELECT <field list>
    FROM   <table>
     [INNER|LEFT]
      JOIN <other table>
        ON <join criteria>
    ...
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2015
    Posts
    7
    I had another go but still can't get it:

    Click image for larger version. 

Name:	sql.png 
Views:	5 
Size:	880.6 KB 
ID:	16253

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    ON children.parentID = parents...
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2015
    Posts
    7
    Still stuck.

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    SELECT <field list>
         , Count(*)
    FROM   <table>
     INNER
      JOIN <other table>
        ON <other table>.<common field> = <table>.<common field>
    GROUP
        BY <field list>
    HAVING Count(*) > 1
    George
    Home | Blog

  7. #7
    Join Date
    Mar 2015
    Posts
    7
    Code:
    SELECT parentName, count(*)
    FROM parents
     INNER
      JOIN children 
       ON (children.parentID = parents.parentID)
    GROUP BY parentName
    HAVING COUNT (*) >= 1
    I tried this. Still getting errors but I think I'm close.

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What errors are you getting?
    George
    Home | Blog

  9. #9
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    The ones to keep George writing here....
    Dave

  10. #10
    Join Date
    Mar 2015
    Posts
    7
    Unfortunately I lost the database as the college's computers have been upgraded, what was the answer?

  11. #11
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    3. I found it on page 173.
    Dave

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •