| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

09-29-11, 15:57
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 6
|
|
|
Converting a sentence into an SQL Query
|
|
I am trying to complete an assignment and I am not having much luck with it.
I have 12 questions I need to convert into queries and hope the some help with one of the will start me in the right direction.
I believe I am supposed to be using Joins to link info from two tables but I can't get it to work.
Here are the two tables-
Gig-
GigId
idvenue
idband
Gigdate-
NumAttendees
band-
idband
bandname
The question I need to convert is-
Which band did not have any gigs?
Any help would be greatly appreciated!
|
|

09-29-11, 18:19
|
|
Resident Curmudgeon
|
|
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
|
|
We need to take this in steps. What SQL statement would produce a list of everything you know about bands? What SQL statement would produce a list of everything you know about gigs?
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
|
|

09-29-11, 18:41
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 6
|
|
|
|
The two queries would be-
select * from band;
select * from gig;
|
|

09-30-11, 05:20
|
|
Jaded Developer
|
|
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
|
|
as you point out you need to do a join between the two tables and as part of that query identify which which bands have no (or a null) gigID
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
|
|

09-30-11, 14:06
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 6
|
|
I can't get the join to work, I have tried it a hundred different ways.
|
|

09-30-11, 14:08
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
Quote:
Originally Posted by midnightkomp
I can't get the join to work, I have tried it a hundred different ways.
|
pls show one or two of them
|
|

09-30-11, 14:14
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 6
|
|
Here is the last one I tried.
Select band.idband, gig.gigdate from gig join band on gig.bandname where gigdate = null;
Thanks
|
|

09-30-11, 14:21
|
|
Jaded Developer
|
|
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
|
|
|
|

09-30-11, 14:36
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 14
|
|
Quote:
Originally Posted by midnightkomp
Here is the last one I tried.
Select band.idband, gig.gigdate from gig join band on gig.bandname where gigdate = null;
|
Try this:
Code:
Select band.idband, gig.gigdate
from gig join band
on gig.bandid = band.bandid
where gigdate is null;
|
|

09-30-11, 15:05
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 6
|
|
I put that in and had to switch the bandid to idband in third line.
Select band.idband, gig.gigdate
from gig join band
on gig.idband = band.idband
where gigdate is null;
It comes up empty string, I believe the code is right but the actual databse does not have null for the bands that do not have gigs. It just does not list them.
I am going to need to adjust the gigdate with something else. How do I get it to list the bandname of the bands not listed?
Thanks for the help so far
|
|

09-30-11, 15:16
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
you are on the right path, but not quite there yet
you need a LEFT OUTER JOIN, for starters
|
|

09-30-11, 15:22
|
|
Jaded Developer
|
|
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
|
|
what relevance has the gigdate column in this query?
you are searching for bands that don't have any matching records in the gig table, so that column will always be null.
you need to refine the join to get the results you want.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
|
|

09-30-11, 15:26
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 6
|
|
The gigdate column only shows the actual dates of the bands that did have a gig. I would think the idband is the key. If a band's id is not listed then they do not have a gig.
|
|

09-30-11, 16:32
|
|
Jaded Developer
|
|
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
|
|
your original question is to find what bands didn't have any gigs
...so why do you think having gigdate in this query is relevant or useful?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|