Please have a look at this sample tables.
Table : users [id | name]
Table: Schools [s_id | s_name | userid]
[CODE=sql]
1 | School A | 1001
2 | School B | 1001
3 | School C | 1002
[/CODE]
I need to join these table records like in this format.
USER-1 | Shcool A, School B
Is this possible with using a query it self ?
here is the sample scripts to test it.
Table : users [id | name]
Code:
1001 | USER-1 1002 | USER-2 1003 | USER-3
Table: Schools [s_id | s_name | userid]
[CODE=sql]
1 | School A | 1001
2 | School B | 1001
3 | School C | 1002
[/CODE]
I need to join these table records like in this format.
USER-1 | Shcool A, School B
Is this possible with using a query it self ?
here is the sample scripts to test it.
Code:
create database sample1
GO
use sample1
GO
create table users(
id int primary key IDENTITY (1001,1),
name varchar(50)
)
GO
insert into users(name)values('USER-1')
insert into users(name)values('USER-2')
insert into users(name)values('USER-3')
GO
create table schools(
s_id int primary key iDENTITY (1,1),
s_name varchar(128),
userid int not null
)
GO
insert into schools(s_name,userid)values('School A','1001')
insert into schools(s_name,userid)values('School B','1001')
insert into schools(s_name,userid)values('School C','1002')
insert into schools(s_name,userid)values('School D','1003')
GO
select * from users
select * from schools
Comment