title: Library database design foreign key
body: <p>I'm designing a library application for my school. We have a 2-3 main libraries and some departments have their own libraries. I wanted to know whether these queries seem correct ?</p>
  
  <pre><code>Libraries 
  ID Name
  1  Walter
  2  Wally
  3  Maths dept library
  
  Books
  ID Book ID  BookName
  1   1       Fundamentals of calculus
  2   1       Mechanics 
  3   2       Fundamentals of calculus
  4   2       Biology
  
  Lib_Book_LookUp
  ID  libId bookId
  1    1     1
  2    1     2
  3    2     1
  4    2     2
  </code></pre>
  
  <p>The two questions I want to solve are:</p>
  
  <ol>
  <li>Find how many copies of a particular book exist</li>
  <li>Find out which libraries have a particular book </li>
  </ol>
  
  <p>Here's what I have:</p>
  
  <pre><code>Select count(Book.bookId) where book.name = "Fundamentals of calculus";
  
  Select count(libId) from Lib_Book_lookUp, Book where Book.BookId = Lib_Book_lookUp.bookId groupBy(libId)
  </code></pre>
  
  <p>My questions regarding these queries:</p>
  
  <ol>
  <li>Does it seem unnecessary to have a separate lookup table and merge the libId into Books table and have it as a foreign key on the book table ? </li>
  <li>Do the queries seem correct ?</li>
  </ol>