Basic SQL Question

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

    #1

    Basic SQL Question

    I have a question on a practice assignment that I can't solve. Can someone
    help me out?

    Question:

    The table Arc(x,y) currently has the following tuples (note there are
    duplicates): (1,2), (1,2), (2,3), (3,4), (3,4), (4,1), (4,1), (4,1), (4,2).
    Compute the result of the query:

    SELECT a1.x, a2.y, COUNT(*)
    FROM Arc a1, Arc a2
    WHERE a1.y = a2.x
    GROUP BY a1.x, a2.y;

    Which of the following tuples is in the result?


    a) (2,3,2)
    b) (2,4,6)
    c) (4,2,6)
    d) (3,2,6)



  • Aggro

    #2
    Re: Basic SQL Question

    KGuy wrote:[color=blue]
    > I have a question on a practice assignment that I can't solve. Can someone
    > help me out?[/color]

    Yes, create the table in question to your database, insert the given
    values to there and then execute the given query and check which of
    given results matches to the actual result.

    This task is so simple that you don't even need brains to solve it,
    since all you have to do is follow the instructions, compare few rows
    and tell what you see.

    If you don't have database, you can get one for free, for example mysql:
    http://www.mysql.com/

    Comment

    • KGuy

      #3
      Re: Basic SQL Question

      > Yes, create the table in question to your database, insert the given[color=blue]
      > values to there and then execute the given query and check which of given
      > results matches to the actual result.[/color]

      Of course, I could do that, but I would like to understand why the output is
      what it is. Sorry if I was unclear. Thanks for the reply.

      -Imran


      Comment

      • Aggro

        #4
        Re: Basic SQL Question

        KGuy wrote:
        [color=blue]
        > Of course, I could do that[/color]

        Don't say you could do that, just do it. When you tell the corrent
        answer, someone might be able explain it. And if want to make a guess,
        be sure not choose wrong one.

        Please understand that if we just give the correct answers it would be
        the same as just shooting you in the head. It would do you more harm
        than good. Point of practise assignments is that you learn by doing them.

        Comment

        • KGuy

          #5
          Re: Basic SQL Question

          >I have a question on a practice assignment that I can't solve. Can someone[color=blue]
          > help me out?[/color]

          Thanks everybody. I managed to solve it by hand using tips from someone
          (Andy Hassall). It takes a while, but at least it's doable and I understand
          it. If the answer is important to you, reply to this post.


          Comment

          Working...