Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for a join

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I have 2 tables and I'm having trouble joining them properly.

I have a table called BookTitles:
id title
-- -----
1 TitleA
2 TitleB
3 TitleC

I have a table of authors
id booktitle_id AuthorName
-- ------------ ----------
1 2 NameA
2 1 NameB
3 2 NameC
4 3 NameD

As you can see, some books have multiple authors (i.e. BookTitle.id = 2)

How can I select from these tables and end up with 2 columns -- one for booktitle and one for authors? If there are 2 authors for a book, I want them to appear in the same field (comma delimited?) in my result set.

Is this possible? Any help would be appreciated...
-erlyhal
 
the join is simple

select a.title,a.authorname
from booktitles a outer join authorname b on a.id = b.booktitle_id
order by a.title

this should also extract all books without authors
(if you want to leave the books without authors use an inner join).

However if you want comma delimited and grouping them together I think you need a stored procedure or T-SQl code.I may be wrong, and some can correct me on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top