473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

MySQL querry

Hey everyone,
I know this isn't a SQL group, but I'm on my colleges news server and they
don't offer one. Hopefully someone here will be able to help me.

I have a database that is normalized with a many-to-one ratio. Basically I
have one table, "concerts", another table "bands_at_concerts", and a final
table, "bands". Concerts has a key CID (concert ID), bands has "bid" (band
ID). "bands_at_concerts" is just two columns, CID and BID, both of which
have several of the same #'s. (For example, many bands play at one
concert, and one band plays at many concerts) I was wondering if there is
a way to retrieve all this information JOINED on to a querry I do to find
information about the concert. ie: SELECT * FROM concert WHERE cid = X <-
Is there a way to change that so that it also somehow returns all the bands
that would be playing there?

Thanks in advance,
-Eric Kincl
Jul 17 '05 #1
4 3017
On Wed, 08 Oct 2003 19:42:22 +0000, Eric Kincl <Er**@Kincl.net> wrote:
Hey everyone,
I know this isn't a SQL group, but I'm on my colleges news server and they
don't offer one. Hopefully someone here will be able to help me.

I have a database that is normalized with a many-to-one ratio. Basically I
have one table, "concerts", another table "bands_at_concerts", and a final
table, "bands". Concerts has a key CID (concert ID), bands has "bid" (band
ID). "bands_at_concerts" is just two columns, CID and BID, both of which
have several of the same #'s. (For example, many bands play at one
concert, and one band plays at many concerts) I was wondering if there is
a way to retrieve all this information JOINED on to a querry I do to find
information about the concert. ie: SELECT * FROM concert WHERE cid = X <-
Is there a way to change that so that it also somehow returns all the bands
that would be playing there?


select bands.*
from concerts
inner join bands_at_concerts using (cid)
inner join bands using (bid)
where cid = X

Unless I've missed the point.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2
Andy Hassall wrote:
On Wed, 08 Oct 2003 19:42:22 +0000, Eric Kincl <Er**@Kincl.net> wrote:
Hey everyone,
I know this isn't a SQL group, but I'm on my colleges news server and they
don't offer one. Hopefully someone here will be able to help me.

I have a database that is normalized with a many-to-one ratio. Basically
I have one table, "concerts", another table "bands_at_concerts", and a
final
table, "bands". Concerts has a key CID (concert ID), bands has "bid"
(band
ID). "bands_at_concerts" is just two columns, CID and BID, both of which
have several of the same #'s. (For example, many bands play at one
concert, and one band plays at many concerts) I was wondering if there is
a way to retrieve all this information JOINED on to a querry I do to find
information about the concert. ie: SELECT * FROM concert WHERE cid = X <-
Is there a way to change that so that it also somehow returns all the
bands that would be playing there?


select bands.*
from concerts
inner join bands_at_concerts using (cid)
inner join bands using (bid)
where cid = X

Unless I've missed the point.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


Hey,
Thanks, it looks like it'll work. One question though. What sort of result
will it return? Will it be multiple lines or what? If it works like I
would like it to, it would be something like one line about the concert and
the rest bands that will be there, or all lines about the concert and each
line would have a different band.

Thanks again,
-Eric Kincl
Jul 17 '05 #3
On Wed, 08 Oct 2003 20:13:57 +0000, Eric Kincl <Er**@Kincl.net_NO_SPAM_> wrote:
Andy Hassall wrote:
On Wed, 08 Oct 2003 19:42:22 +0000, Eric Kincl <Er**@Kincl.net> wrote:
Hey everyone,
I know this isn't a SQL group, but I'm on my colleges news server and they
don't offer one. Hopefully someone here will be able to help me.

I have a database that is normalized with a many-to-one ratio. Basically
I have one table, "concerts", another table "bands_at_concerts", and a
final
table, "bands". Concerts has a key CID (concert ID), bands has "bid"
(band
ID). "bands_at_concerts" is just two columns, CID and BID, both of which
have several of the same #'s. (For example, many bands play at one
concert, and one band plays at many concerts) I was wondering if there is
a way to retrieve all this information JOINED on to a querry I do to find
information about the concert. ie: SELECT * FROM concert WHERE cid = X <-
Is there a way to change that so that it also somehow returns all the
bands that would be playing there?


select bands.*
from concerts
inner join bands_at_concerts using (cid)
inner join bands using (bid)
where cid = X

Unless I've missed the point.


Thanks, it looks like it'll work. One question though. What sort of result
will it return? Will it be multiple lines or what? If it works like I
would like it to, it would be something like one line about the concert and
the rest bands that will be there, or all lines about the concert and each
line would have a different band.


It'll be each bands row that is part of the relation with the concert.

If you want the concert information too, add it to the select list, it'll be
repeated per band.

It doesn't make any sense to be getting one row for the concert and and
several for the bands in the same result set; you can't have rows of different
'types' in the same result set.

If you only want to fetch the concert fields once, do two queries; the one
above to get band information, and 'select * from concerts where CID = X' to
get concert information.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #4
Andy Hassall wrote:
On Wed, 08 Oct 2003 20:13:57 +0000, Eric Kincl <Er**@Kincl.net_NO_SPAM_>
wrote:
Andy Hassall wrote:
On Wed, 08 Oct 2003 19:42:22 +0000, Eric Kincl <Er**@Kincl.net> wrote:

Hey everyone,
I know this isn't a SQL group, but I'm on my colleges news server and
they
don't offer one. Hopefully someone here will be able to help me.

I have a database that is normalized with a many-to-one ratio.
Basically I have one table, "concerts", another table
"bands_at_concerts", and a final
table, "bands". Concerts has a key CID (concert ID), bands has "bid"
(band
ID). "bands_at_concerts" is just two columns, CID and BID, both of
which
have several of the same #'s. (For example, many bands play at one
concert, and one band plays at many concerts) I was wondering if there
is a way to retrieve all this information JOINED on to a querry I do to
find
information about the concert. ie: SELECT * FROM concert WHERE cid = X
<- Is there a way to change that so that it also somehow returns all the
bands that would be playing there?

select bands.*
from concerts
inner join bands_at_concerts using (cid)
inner join bands using (bid)
where cid = X

Unless I've missed the point.


Thanks, it looks like it'll work. One question though. What sort of
result
will it return? Will it be multiple lines or what? If it works like I
would like it to, it would be something like one line about the concert
and the rest bands that will be there, or all lines about the concert and
each line would have a different band.


It'll be each bands row that is part of the relation with the concert.

If you want the concert information too, add it to the select list, it'll
be
repeated per band.

It doesn't make any sense to be getting one row for the concert and and
several for the bands in the same result set; you can't have rows of
different 'types' in the same result set.

If you only want to fetch the concert fields once, do two queries; the
one
above to get band information, and 'select * from concerts where CID = X'
to get concert information.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


Alright dude! Thanks! It works great. For future reference to those of
you out there, it returns 1 row per multiple instance (in this case 1 row
per band.) This means its returning the other info (this case, the concert
info) multiple times, but you can obviously just ignore that.
Jul 17 '05 #5

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

Similar topics

2
by: Eric Kincl | last post by:
Hello, I have an array of data in PHP. I would like to insert each member of the array into it's own row in SQL. The array is of variable length, so it would have to be dynamic code. How would...
0
by: Costa Lino | last post by:
Hi All, I have a DataSet with xml file and I want to make a querry like this DataView dv = new DataView(mytable); dv.RowFilter = " Impression < ( MaxImpressions) "; Impression et...
5
by: Clownfish | last post by:
OK, I'm having a brain freeze. I have a table like this: Office Name Phone ---------------------------------- SG Larry 555-1212 SG Moe 553-4444 SG Curly ...
1
Steve Kiss
by: Steve Kiss | last post by:
Hi. I am developping a site for which one of the pages uses querry strings to pass some parameters. I can use the querry strings if I call the page from a plain html anchor. However, when I add the...
1
by: nj2md | last post by:
Can some one assist with a querry. I need to know the code to querry a database to find the number of female and males that make over 50K a year and how to get capital gains and loses from the same...
1
by: saagar | last post by:
Is it possible to generate an xml file using some mysql querry which can be used with languages like java i have tried it with --xml but what i want is the output of a querry to be converted into...
4
by: cjacks | last post by:
I have 2 tables linked by a common field. users ------ id ....more columns users_profiles -------------- users_id
2
by: dipalichavan82 | last post by:
i came across a article, where it was mentioned if we want a dynamic querry to fire then use parameterized querry e.g. string inputcity=textbox.text; SqlCommand cmd = new SqlCommand("select * from...
0
by: tedpottel | last post by:
Hi I am trying to right a script to keep a local copy of my mysql database in a local access file. I was able to do this in Access visual basic, but cannot get it to work in python. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.