Unix Technical Forum

Need help Joining tables

This is a discussion on Need help Joining tables within the SQL Server forums, part of the Microsoft SQL Server category; --> I'm need to get the [description] from the classifications table Trying to join it to another table (titleclassification) but ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 02:43 PM
JJ297
 
Posts: n/a
Default Need help Joining tables

I'm need to get the [description] from the classifications table
Trying to join it to another table (titleclassification) but I don't
need info from that table. I'm getting the results but it's sending
back repeat data. Any suggestions?

SELECT
Titles.titleid, titles.title, titles.[description],
resources.quantityowned, classifications.[description]

FROM
Titles inner join resources on titles.titleid = resources.titleid,
classifications inner join titleclassification on
classifications.classificationid =
titleclassification.classificationid

Thanks so much!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 02:43 PM
Roy Harvey (SQL Server MVP)
 
Posts: n/a
Default Re: Need help Joining tables

Without DDL for all the tables, including all keys, all I can do is
guess. In this case I guessed that the titleclassification table
includes titleid, and that the key is (titleid

SELECT A.titleid,
A.title,
A.[description],
B.quantityowned,
classifications.[description]
FROM Titles as A
JOIN resources as B
ON A.titleid = B.titleid
JOIN titleclassification as C
ON A.titleid = C.titleid
JOIN classifications as D
ON D.classificationid = C.classificationid

Roy Harvey
Beacon Falls, CT

On Wed, 24 Oct 2007 08:42:09 -0700, JJ297 <nc297@yahoo.com> wrote:

> I'm need to get the [description] from the classifications table
>Trying to join it to another table (titleclassification) but I don't
>need info from that table. I'm getting the results but it's sending
>back repeat data. Any suggestions?
>
>SELECT
> Titles.titleid, titles.title, titles.[description],
>resources.quantityowned, classifications.[description]
>
> FROM
> Titles inner join resources on titles.titleid = resources.titleid,
>classifications inner join titleclassification on
>classifications.classificationid =
>titleclassification.classificationid
>
>Thanks so much!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 02:43 PM
JJ297
 
Posts: n/a
Default Re: Need help Joining tables

On Oct 24, 11:50 am, "Roy Harvey (SQL Server MVP)"
<roy_har...@snet.net> wrote:
> Without DDL for all the tables, including all keys, all I can do is
> guess. In this case I guessed that the titleclassification table
> includes titleid, and that the key is (titleid
>
> SELECT A.titleid,
> A.title,
> A.[description],
> B.quantityowned,
> classifications.[description]
> FROM Titles as A
> JOIN resources as B
> ON A.titleid = B.titleid
> JOIN titleclassification as C
> ON A.titleid = C.titleid
> JOIN classifications as D
> ON D.classificationid = C.classificationid
>
> Roy Harvey
> Beacon Falls, CT
>
>
>
> On Wed, 24 Oct 2007 08:42:09 -0700, JJ297 <nc...@yahoo.com> wrote:
> > I'm need to get the [description] from the classifications table
> >Trying to join it to another table (titleclassification) but I don't
> >need info from that table. I'm getting the results but it's sending
> >back repeat data. Any suggestions?

>
> >SELECT
> > Titles.titleid, titles.title, titles.[description],
> >resources.quantityowned, classifications.[description]

>
> > FROM
> > Titles inner join resources on titles.titleid = resources.titleid,
> >classifications inner join titleclassification on
> >classifications.classificationid =
> >titleclassification.classificationid

>
> >Thanks so much!- Hide quoted text -

>
> - Show quoted text -


Ron, thanks for your help. The key for the titleclassification table
is titleclassID

When I entered what you wrote in query analyzer I got...

The column prefix 'classifications' does not match with a table name
or alias name used in the query.

Any ideas?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 02:43 PM
Roy Harvey (SQL Server MVP)
 
Posts: n/a
Default Re: Need help Joining tables

On Wed, 24 Oct 2007 09:08:25 -0700, JJ297 <nc297@yahoo.com> wrote:

>The key for the titleclassification table
>is titleclassID


Then either I do not understand the purpose of the table (likely, as I
can only guess) or the table had an ID column stuck on as a key out of
blind reflex. My assumption was that it was a "junction" table used
to make a many-to-many relationship between title and classification.
Such a table would properly have a key consisting of the key column(s)
of the Titles table plus the key column(s) of the Classifications
table.

>When I entered what you wrote in query analyzer I got...
>
>The column prefix 'classifications' does not match with a table name
>or alias name used in the query.


I missed changing one reference to use the alias.

SELECT A.titleid,
A.title,
A.[description],
B.quantityowned,
D.[description]
FROM Titles as A
JOIN resources as B
ON A.titleid = B.titleid
JOIN titleclassification as C
ON A.titleid = C.titleid
JOIN classifications as D
ON D.classificationid = C.classificationid

Roy Harvey
Beacon Falls, CT
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2008, 02:43 PM
JJ297
 
Posts: n/a
Default Re: Need help Joining tables

On Oct 24, 1:05 pm, "Roy Harvey (SQL Server MVP)"
<roy_har...@snet.net> wrote:
> On Wed, 24 Oct 2007 09:08:25 -0700, JJ297 <nc...@yahoo.com> wrote:
> >The key for the titleclassification table
> >is titleclassID

>
> Then either I do not understand the purpose of the table (likely, as I
> can only guess) or the table had an ID column stuck on as a key out of
> blind reflex. My assumption was that it was a "junction" table used
> to make a many-to-many relationship between title and classification.
> Such a table would properly have a key consisting of the key column(s)
> of the Titles table plus the key column(s) of the Classifications
> table.
>
> >When I entered what you wrote in query analyzer I got...

>
> >The column prefix 'classifications' does not match with a table name
> >or alias name used in the query.

>
> I missed changing one reference to use the alias.
>
> SELECT A.titleid,
> A.title,
> A.[description],
> B.quantityowned,
> D.[description]
> FROM Titles as A
> JOIN resources as B
> ON A.titleid = B.titleid
> JOIN titleclassification as C
> ON A.titleid = C.titleid
> JOIN classifications as D
> ON D.classificationid = C.classificationid
>
> Roy Harvey
> Beacon Falls, CT


Thanks Roy I am now getting the results I need. I see what I did
wrong.

Thanks so much for your help!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:39 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com