Write an SQL query that returns the studentid and name of students who checked o
ID: 3596284 • Letter: W
Question
Write an SQL query that returns the studentid and name of students who checked out the textbook of a course that they did not enroll in.
book bookid title Introduction of Algorithms rice total copies 84.66 Database System Concepts74.99 Stochastic Calculus for Financ41.02 Stochastic Calculus for Finance II 55.22 course title Algorithms DB Organization Advanced DB Organization Math Finance I Math Finance II faculty enroll studentid courseid student studentid facultyid name gpa Tom 3.3 John3.8 Mary 3.0 Kris 3.6 Alex3.5 James 70000 Sarah 60000 ay 80000 Rache 70000 Pau85000 book_ checkout bookid studentid 2017-08-29 2017-09-02 2017-09-07Explanation / Answer
--Here we are joining the three tables and calculating the ids which are not matching with the course ids.
SELECT distinct
studentid,name from
(SELECT student.studentid,student.name,book_checkout.bookid,enroll.courseid,enroll.courseid as cour
FROM book_checkout
INNER JOIN student ON student.studentid=book_checkout.studentid
INNER JOIN enroll ON student.studentid=enroll.studentid
INNER JOIN enroll ON textbookid=book_checkout.bookid) where bookid<>cour
Output:-
-------------
studentid name
4 Kris
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.