473,609 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)

Jul 23 '05 #1
5 3356
KGuy wrote:
I have a question on a practice assignment that I can't solve. Can someone
help me out?


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/
Jul 23 '05 #2
> 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.


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
Jul 23 '05 #3
KGuy wrote:
Of course, I could do that


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.
Jul 23 '05 #4
>I have a question on a practice assignment that I can't solve. Can someone
help me out?


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.
Jul 23 '05 #5
On Sun, 23 Jan 2005 13:00:20 -0500, KGuy wrote:

(crossposting removed)
I have a question on a practice assignment that I can't solve. Can someone
help me out?
Hi KGuy,

In a few weeks time, you'll have a test. If you don't learn to work out
your assignments now, you'll certainly fluke the test.

And if you're lucky and pass the test, you'll be in even more trouble when
you're hired and you have to debug some real SQL.

Question:

The table Arc(x,y) currently has the following tuples (note there are
duplicates) (snip)

If there are duplicates, you don't have a table at all. A collection of
data that may hold duplicates is a heap. I'm truly amazed that there are
still schools where SQL is taught with text books that don't include a
primary key on every table in every example or every assignment.

(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;
Almost all professionals prefer the (more verbose, but better documenting)
infixed join notation. For outer join, the infixed notation is the only
way to avoid ambiguity. For inner joins, beth versions are allowed, but
the infixed notation is more popular. Also, avoiding the optional AS
between table name and table alias is not recommended either!

SELECT a1.x, a2.y, COUNT(*)
FROM Arc AS a1
INNER JOIN Arc AS a2
ON a1.y = a2.x
GROUP BY a1.x, a2.y;

This is how the query should (IMO) appear in a decent studybook.

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)


Easy to work out, actually. As an example, I'll show you why the answer
isn't a. You can then work out the three remaining options.

Each row in the output that shows 2 as the first value has a1.x=2. This
must stem from the row (2, 3), as that is the only row with an x value of
2. The join condition (a1.y=a2.x) means that the a2 row must have an x
value of 3 (as the y value in the a1 row is 3). Two rows qualify: (3, 4)
and (3, 4). Both have an y value of 4, so before grouping, there are 2
rows with a1.x=2 and a2.y=4. After grouping, this is 1 group with a row
count of 2. The result set should contain (2, 4, 2) as the only row
starting with 2.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2473
by: pauldepstein | last post by:
I am reading Grimshaw and Ortega's "C++ and Numerical Methods." They construct a vector class which contains the variable vec, a float* variable where the length of the array (number of components in the vector) is given by the variable name veclength. That is what I _do_ understand. What I don't understand is the coding for the default constructor which includes vec=0; What does it mean for a pointer to be equal to 0? Presumably...
6
5110
by: DH | last post by:
I have a VERY basic question about figuring database size. I've inherited a database which is generally similar to this basic one: Item, Red, Blue, Green, Yellow (text), (int),(int),(int),(int) box, 1,0,0,2 hat, 0,0,0,1 car, 3,0,0,0 This format leads to a lot of zeros in the rows which take up a lot of
9
2231
by: Malcolm | last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC interpreter. The question is, how is it most useful? At the moment I have a function int basic(const char *script, FILE *in, FILE *out, FILE *err); It returns 0 on success or -1 on fail.
4
2220
by: Ramesh | last post by:
hi, Let me ask some basic questions. Can anybody explain me about the following questions: 1. When we have to create sn key? Whenever we compiled Component we have to create or it is a one time process? 2. What information contained in sn key. I gone through that it is having public key. How it is using this key to intract with client. 3. When we have to run gacutil.exe file. Whenever we
13
15547
by: Pete | last post by:
I'm cross posting from mscom.webservices.general as I have received no answer there: There has been a number of recent posts requesting how to satisfactorily enable BASIC authorization at the HTTP level but as yet no fully useful answer. I too have been trying to call an apache/axis webservice which desires a username/password from my C# Client. (ie the equivalent of _call.setUsername("Myname") name from within a Java client proxy)...
5
1803
by: Aussie Rules | last post by:
Hi, Having a mental block on this one. Have done it before but can't rack my brain on how... I have an object, with a bunch on property, and I add that object to a combo box. I want the property '.fulladdress' to be the value that appears in the drop downs text section. How to I set that parameter to be the one shown inthe drop down
4
1723
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, - Programming Visual Basic by Balena (MS Press) and - Visual Basic 2005 by Willis (WROX), but they don't go into the forms design aspects and describing the various controls at all. What bookscan I get that will cover that?
1
1484
by: frankhanretty | last post by:
Do I have to install Visual basic on the remote terminals as I did on the server? I have an visual basic 5 application running fine on my client's server and he is now networked. He wants to run the visual basic applicaton that runs on his server on the remote terminals. (he has two networked to his server) My question is do I now have to install visual basic on the two terminals also? Thank you in advance to anyone who can answer this for...
4
3087
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these applications into Visual Basic.Net. My managers main thought is that Visual Basic 6 is (or has!) stopped being supported by Microsoft.
3
1935
by: Scott Stark | last post by:
Hello, I'm trying to get a better handle on OOP programming principles in VB.NET. Forgive me if this question is sort of basic, but here's what I want to do. I have a collection of Employee objects that I can iterate through relatively easily. I've included code at the bottom of this message. I can pretty easily iterate through my employee objects like so: Dim theEmployees As Employees = New Employees
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.