Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
I have two tables 'Student' and 'Book' created in a SQL databse. 'Student' table consists of 'Roll number(Primary Key), Name' columns and 'Book' table consists of 'Book number(Primary key), Book name, Author name'. How can I join the two tables such that I know which books are issued to which Student.. Actually I will make Student Roll number feed into my program and then check the books issued to that student..
Help required..

Thank You..
Posted
Updated 23-Jul-13 23:30pm
v3

The simple answer is :
you need a 3rd table StudentHasBorrowedBook with 2 PKs colums Roll number and Book number.

That said the question might become much more complicated if you have 2 prints of the same 'Book'
 
Share this answer
 
SELECT Student.Rollnumber, Book.Bookname, Student.Studentname
FROM Student
INNER JOIN Book
ON Student.Booknumber=Book.Booknumber;
 
Share this answer
 
Comments
Ashish sharma 26-Jul-13 11:51am    
What Does this do?
the query is getting executed but seems to do nothing..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900