i have four tables eg
Student table - table
ID -
Name -
Sit table
ID
Stand table
ID
Jump Table
ID
where Student table is Master and all other are foriegn key to ID column in other tables.
Student table
1 Ram
2 Venu
3 Mahesh
4 Dinesh
5 Rahim
Sit table
1
2
Stand table
3
Jump table
4
1
I want a query which will result in following structure
StudentID StudentName ActivityDone
1 Ram Sit
2 Venu Sit
3 Mahesh Stand
4 Dinseh Jump
5 Rahim None
6 Ram Jump
Please can any one help me...
AshishPosted Apr 22, 2014, 1:37 AM
( select student.id,student.name,stand.activity from Student right join stand on student.id = stand.id )
union ( select student.id,student.name,jump.activity from Student right join jump on student.id = jump.id )
This query will produce your desired output.
AshishPosted Apr 21, 2014, 9:30 AM
AshishPosted Apr 21, 2014, 9:29 AM
AshishPosted Apr 21, 2014, 9:28 AM
(
id int not null primary key , name varchar(10)
)
create table sit
(
id int foreign key references student(id),
activity varchar(5)
)
create table stand
(
id int foreign key references student(id),activity varchar(5)
)
create table jump
(
id int foreign key references student(id),activity varchar(5)
)
insert into student(id,name) values(1,'RAM')
insert into student(id,name) values(2,'VENU')
insert into student(id,name) values(3,'MAHESH')
insert into student(id,name) values(4,'DINESH')
insert into student(id,name) values(5,'RAhiM')
insert into sit(id,activity) values(1,'sit')
insert into sit(id,activity) values(2,'sit')
insert into stand(id,activity) values(3,'stand')
insert into jump(id,activity) values(4,'jump')
insert into jump(id,activity) values(1,'jump')