-1

I have 2 tables as such:

StudentID Email
1 him@school.edu
2 her@school.edu
Book Title Borrowed By (Student ID) Borrowed Date
Some Book 13 10/10/2021
Other Book 456 10/15/2021

I want to make a single SQL query to return the email of the student and borrowed date for a specific book title.

Something like

SELECT 
    *
FROM
    student_table
WHERE
    StudentID = (SELECT 
            StudentID
        FROM
            borrowed_table
        WHERE
            BookTitle = 'Some Book');

but this would only return the Email. I want to return the borrowed date as well. How can I combine the results of both queries?

Can this be done without specifying the columns (UNION of *) ?

nbk
  • 45,398
  • 8
  • 30
  • 47
pete65
  • 13
  • 4

2 Answers2

0

Join both tables

SELECT 
    st.*,bt.`Borrowed Date`
FROM
    student_table st
    INNER JOIN borrowed_table bt ON st.StudentID = bt.StudentID
WHERE
  bt.BookTitle = 'Some Book';
nbk
  • 45,398
  • 8
  • 30
  • 47
0

Select st.BookTitle, st.BorrowedBy, bt.BorrowedDate from Student_table st inner join borrowed_table bt on st.StudentID = bt.StudentID where bt.BookTitle = 'Some book title'