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!

Concatenating Questions 2

Status
Not open for further replies.

Guru7777

Programmer
Dec 10, 2003
331
US
Hello All,

Does anyone know a better way to do this?

I have a query where there is a one-to-many relationship. For a generic example, one author to many books.

I want to write a query where I can have the result like below

Author Books
------- --------
John Smith Some Book, Some Other Book, YA Book
Jill Jones Great Book, Average Book, Bad Book

where as a normal query with normal joins would return

Author Book
------- ---------
John Smith Some Book
John Smith Some Other Book
John Smith YA Book
Jill Jones Great Book
Jill Jones Average Book
Jill Jones Bad Book

Does that make sense?

I can use a cursor to take an author id, then query the book table, concatenating the names, then SELECT that out for the column.

If at all possible, for efficiency's sake, I would like to use a set-based solution if one is available and ditch the cursor.

Do any of you have any suggestions?

Thank you very much.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
thread183-1159740

Ignorance of certain subjects is a great part of wisdom
 
sorry jbenson001, I did not notice your post. This question seesm to be popping up more than usual lately...

Ignorance of certain subjects is a great part of wisdom
 
Thanks alot jbenson. I had no idea how to even phrase this question in such a way as to search for it.


Thanks again.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Alex.. LOL no problem.. and yes.. it has been coming up quite alot lately

Guru.. sometimes the search is querky.. but usually someone will link you to a thread that may help if there is one out there...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top