Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Statement, INNER JOIN?

Author  Topic 

gazzou
Starting Member

3 Posts

Posted - 2005-04-05 : 23:05:10
I have 3 tables as follow:
tblDocument(DocumentId,DocumentTitle)
tblDocumentAttachment(DocumentAttachmentId, DocumentAttachmentTitle)
tblDocumentAttachmentLink(DocumentId, DocumentAttachmentId)

tblDocumentAttachmentLink shows which documents are associated together

This is my current SQL Statement:

SQLFull = "SELECT * FROM tblDocumentAttachment, tblDocumentAttachmentLink WHERE tblDocumentAttachment.DocumentAttachmentID = tblDocumentAttachmentLink.DocumentAttachmentID AND tblDocumentAttachmentLink.DocumentID = " & int(DocumentId)

Currently I'm getting everything from tblDocumentAttachment (given DocumentId) where the conditions apply(which is what I want) but I'm also getting the content of tblDocumentAttachmentLink, which I don't want. I only want to use it to get the proper data.

Does anyone know where I'm going with this?

Any help would be appreciated,

Thanks

Gazzou

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-04-06 : 00:40:25
Use a column list.


SELECT
d.DocumentId, d.DocumentTitle, da.DocumentAttachmentId, da.DocumentAttachmentTitle
FROM
tblDocument d
INNER JOIN tblDocumentAttachmentLink dal ON d.DocumentId = dal.DocumentId
INNER JOIN tblDocumentAttachment da ON dal.DocumentAttachmentId = da.DocumentAttachmentId
WHERE
blah, blah, blah


You might want to pick up a good beginners SQL book. "Learn Transact-SQL in 21 Days" By Sam's is pretty good. Also, anything by Ken Henderson is great.

In addition, you need to start using stored procedures. If you don't know what they are, buy the book.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

gazzou
Starting Member

3 Posts

Posted - 2005-04-06 : 09:51:56
Thanks for the reply,

What you wrote will probably work, but I was wondering if there is a way to SELECT * FROM tblDocumentAttachment instead of going and selecting all individual columns, I have lots of columns, that's why.

Thanks

Gazzou
Go to Top of Page

rfrancisco
Yak Posting Veteran

95 Posts

Posted - 2005-04-06 : 10:00:09
You can use SELECT tblDocumentAttachment .* FROM tblDocumentAttachment to get just the columns of this table in your output.
Go to Top of Page

gazzou
Starting Member

3 Posts

Posted - 2005-04-06 : 10:12:01
Excellent, that's what I wanted. Thanks a million. rFrancisco, I'll consider buying those books, thanks for the advice.

Gazzou
Go to Top of Page
   

- Advertisement -