SELECT student.name
FROM student
WHERE student.email = copy.owner AND copy.book = "978-0262033848"
OR
SELECT student.name
FROM student
WHERE student.email = loan.borrower AND loan.book = "978-0262033848";
In this code, I tried to combine two queries. It is displaying an error and I would like to know what is the mistake in using it this way
CodePudding user response:
My best guess is that this does what you want:
SELECT s.name
FROM student s
WHERE EXISTS (SELECT 1
FROM copy c
WHERE c.email = c.owner and c.book = '978-0262033848'
) OR
EXISTS (SELECT 1
FROM loan l
WHERE s.email = l.borrower and l.book = '978-0262033848'
);
This select students that are in the loan
or copy
tables with the specified book.