Retrieve Data from Different Tables (SQL Server) -


i have 4 tables in sql server database following schema:

  1. attendance

    create table [dbo].[attendance] ( [attendanceid] uniqueidentifier default (newid()) not null, [courseid]     uniqueidentifier not null, [studentid]    uniqueidentifier not null, [subjectid]    uniqueidentifier not null, [semester]     int              not null, [month]        nvarchar (50)    not null, [count]        int              not null, constraint [pk_attendance] primary key nonclustered ([attendanceid] asc), constraint [fk_attendance_student] foreign key ([studentid]) references [dbo].[student] ([studentid]) ); 
  2. course

    create table [dbo].[course] ( [courseid] uniqueidentifier default (newid()) not null, [name]     nvarchar (50)    not null, constraint [pk_course] primary key nonclustered ([courseid] asc) ); 
  3. student

    create table [dbo].[student] ( [studentid] uniqueidentifier default (newid()) not null, [courseid]  uniqueidentifier not null, [name]      nvarchar (100)   not null, [rollno]    int              not null, [semester]  int              not null, constraint [pk_student] primary key nonclustered ([studentid] asc), constraint [fk_student_course] foreign key ([courseid]) references [dbo].[course] ([courseid]) ); 
  4. subject

    create table [dbo].[subject] ( [subjectid] uniqueidentifier default (newid()) not null, [courseid]  uniqueidentifier not null, [name]      nvarchar (100)   not null, [semester]  int              not null, constraint [pk_subject] primary key nonclustered ([subjectid] asc), constraint [fk_subject_course] foreign key ([courseid]) references [dbo].[course] ([courseid]) ); 

i need create attendance report in following format:

course name | student name | subject name | semester | month | count

please tell me sql query need use , if there's change in schema required suggest same.

i'm looking forward have replies.

thanks,

you need use join in query returns rows match [studentid] attendance table.

e.g.

select c.coursename, s.studentname, u.subjectname, u.semester, a.month, a.count student s      join attendance on s.studentid = a.studentid     join course c on a.courseid = c.courseid     join subject u on c.courseid = u.courseid 

something along these lines return rows match


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -