I'm building asp.net mvc app, and I'm having trouble writing SQL stored procedure on multiple tables.
I have 7 different tables, all connected to each other.
Customer
Id
Name
CustomerBook
Id
CustomerId
BookId
Book
Id
Name
BookType
Id
BookId
TypeId
Type
Id
Name
BookCategory
BookId
CategoryId
Category
Id
Name
It looks something like that.
CustomerBook.CustomerId = Customer.Id
CustomerBook.BookId = Book.Id
BookCategory.BookId = Book.Id
BookCategory.CategoryId = Category.Id
BookType.BookId = Book.Id
BookType.TypeId = Book.Id
if im not mistaken.
What i want to do now, is write stored procedure that would get and display all the books that was "bought" by specific user.
I would like to display:
Book name
Book type
Book category
...for each and every user, that is currently logged into session.
Later i would like to get data into controller...but thats a problem for another day.
Since im pretty new to procedures and only know a little SQL, i would really appreciate your help!
This is what i've tried so far:
CREATE PROCEDURE [dbo].[getBookByCustomerId]
@Id int
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM [Customer] WHERE Id = @id
END
and now im stuck...