Top 100 sql server queries interview questions


SQL Server Advanced Questions - 'Join' questions


61) Select FirstName, Lastname, Scholarship amount from tblStudent and tblScholarship table for all students even if they didn't get Scolarship.
1
2
Select Firstname, Lastname, Scholarship_Amount from tblStudent A left join tblScholarship
 B on A.StudentId = B.Student_ref_id
62) Select FirstName, Lastname, Scholarship amount from tblStudent and tblScolarship table for those students who got Scolarship amount.
1
2
Select Firstname, Lastname, Scholarship_Amount from tblStudent A Inner join tblScholarship 
B on A.StudentId = B.Student_ref_id
63) Select FirstName, Lastname, Scholarship amount from tblStudent and tblScholarship table for those students who got Scolarship amount greater than 1200.
1
2
Select Firstname, Lastname, Scholarship_Amount from tblStudent A Inner join tblScholarship 
B on A.StudentId = B.Student_ref_id and Scholarship_Amount > 1200
64) Select FirstName, Lastname, Scholarship amount from tblStudent and tblScholarship table for those students who got Scolarship amount using right join.
1
2
Select Firstname, Lastname, isnull(Scholarship_Amount,0) from tblStudent A right join 
tblScholarship B on A.StudentId = B.Student_ref_id
65) Select FirstName, Lastname, Scholarship amount from tblStudent and tblScholarship table for all students even if they didn't get Scolarship amount and set Scolarship amount as 0 for those students who didn't get Scolarship amount.
1
2
Select Firstname, Lastname, ISNULL(Scholarship_Amount,0) from tblStudent a left join
tblScholarship B on A.StudentId = B.Student_ref_id
66) Write a query to find out the studentname who has not received any scholarship amount, and display 0 in front of his name.
1
2
3
Select Firstname, ISNULL(Scholarship_Amount, 0) As [Scholarship Amount]
from tblStudent A Left Outer Join [tblScholarship] B on 
A.StudentId = B.Student_ref_id where Scholarship_Amount is null
« 1 2 3 4 5 6 »  

Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer & technology lovers. http://www.techstudy.org/.