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==
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==