For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > January 2005 > Basic SQL Question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Basic SQL Question
KGuy

2005-01-23, 8:57 pm

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)


Hal Halloway

2005-01-23, 8:57 pm

KGuy wrote:
> 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)
>
>


Could you actually put the vaules in a MYSQl table then run the SQL?
That way you'd know for sure.
Andy Hassall

2005-01-23, 8:57 pm

On Sun, 23 Jan 2005 12:55:53 -0500, "KGuy" <KGuy.911@hotmail.com> wrote:

>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)


Since it's an assignment then posting the answer isn't going to be much use to
you, so what have you tried? What bits in particular don't you understand? Do
you have a database available? If so, you can run the query, and start breaking
it down into smaller pieces.

Or write down the contents of the table on paper and start working out the
reults of the query by hand - without the COUNT(*) and GROUP BY there's only 19
rows, although there's 81 if you miss out the WHERE clause.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
KGuy

2005-01-23, 8:57 pm

> Could you actually put the vaules in a MYSQl table then run the SQL? That
> way you'd know for sure.


The thing is that I don't just want the answer. I want to understand it. But
thanks for replying.


KGuy

2005-01-23, 8:57 pm

> Since it's an assignment then posting the answer isn't going to be much
> use to
> you, so what have you tried? What bits in particular don't you understand?
> Do
> you have a database available? If so, you can run the query, and start
> breaking
> it down into smaller pieces.


Yes, I do have a database available. I wasn't simply looking for the answer
because the database could help me with that.

> Or write down the contents of the table on paper and start working out the
> reults of the query by hand - without the COUNT(*) and GROUP BY there's
> only 19
> rows, although there's 81 if you miss out the WHERE clause.


Thanks! I finally got it using your hints. But writing it all by hand takes
a while!

-Imran


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com