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 2005 Forums
 Transact-SQL (2005)
 Select query to get child records

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2007-06-29 : 14:42:05
i need a sql select query. which brings data from master table and childtable.

****************************************************************
select master.projectname, master.documentdate, child.supervisorname from tblMasterProjectinfo master, tblProjSupervisors child
where master.Projid = child.projid
****************************************************************

please i have multiple rows in the child table for each master record ID., how can i bind all of the rows supervisor name from child, into one piece of data comma seperated.

can you please help, I am very confused.

Thank you very much for the information.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-29 : 14:53:14
provide some sample data from each of the tables and expected output.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2007-06-29 : 15:08:32
Hello Dinaker,

Here is the Sample data i put, please help:

***************************************************************************************************************
Master table (tblMasterProjectInfo)

projid - Projectname - documentdate
12 - School Board Project - 05/02/07

15 - Liberty Communications - 06/01/07

***************************************************************************************************************

Now i am creating child records for (tblProjSupervisors)

ProjSupervisorID - ProjID - Supervisorname - SupervisorEmail
1 - 12 - Manuel Ruiz - mruiz@metabox.com
2 - 12 - Luis Alvarez - lalvarez@florida.com
3 - 12 - Raj Kumar - rkumar@myflorida.com

4 - 15 - Frank lache - flache@lacheweb.com
5 - 15 - Mike Lee - mlee@stellar32.com


****************************************************************************************************************

Now when i execute the folowing query:
****************************************************************
select master.projectname, master.documentdate, child.supervisorname from tblMasterProjectinfo master, tblProjSupervisors child
where master.Projid = child.projid
****************************************************************


i am expecting the data as follows:
-----------------------------------------------------------------

1.) School Board Project - 05/02/07 - Manuel Ruiz, Luis Alvarez, Raj Kumar

2.) Liberty Communications - 06/01/07 - Frank Lache, Mike Lee

**************************************************************************

Thank you very much for the information/help.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-29 : 23:54:31
If you dont use any front end
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2007-06-30 : 08:08:16
Wow.. Madhivanan, thank you very much for providing the link. it has excellent info.

quote:
Originally posted by madhivanan

If you dont use any front end
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page
   

- Advertisement -