Ok, so i want to populate a gridview with a rather complex statement that i have no idea how to get, I dont even know if its possible. five tables and a view are involved, these arent all the fields in the tables but just to make things clearer, i only put the required fields.
Student Table:-
Student_ID
Specialization_ID
Specialization Table:-
ID
Specialization_Name
Department_ID
Staff Table:-
ID
Staff_ID
Department_ID
Department Table:-
ID
Department_Name
Survey Table:- (Username
is the uploader)
ID
Username
Users View:- (Here the Username
, Password
is taken from both the student table and the staff table)
Username
Password
UserType
This is how i created the view:-
CREATE View [Users] as
Select Student_ID as Username, Password,'STU' as UserType from Student
union
Select Staff_ID, Password, 'STF' as UserType from Staff
Now, considering that when a staff member signs in, his username is stored in session Session["Username"]
, what i want to pull from the database, are all the surveys that are uploaded by users (only students) that have a specialization that belongs to the current user's department. considering that all relationships (foreign keys) are set, what is the sql query i should use? or the method at least.