Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:46:15+00:00 2026-06-13T00:46:15+00:00

I’m designing a library application for my school. We have a 2-3 main libraries

  • 0

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 ?

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

The two questions I want to solve are:

  1. Find how many copies of a particular book exist
  2. Find out which libraries have a particular book

Here’s what I have:

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)

My questions regarding these queries:

  1. 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 ?
  2. Do the queries seem correct ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:46:15+00:00Added an answer on June 13, 2026 at 12:46 am

    Your first query is missing a FROM clause. You could also do COUNT(*), but it doesn’t particularly matter in this case:

     SELECT count(Book.bookId) FROM Books WHERE BookName = "Fundamentals of calculus";
    

    To find out which libraries have a particular book, you don’t need a COUNT() aggregate. Instead you need a WHERE clause with your join. The COUNT() would tell you how many libraries have a book, but not which libraries. For that you want a query which returns Libraries.Name.

    SELECT
      /* Return library names */
      Libraries.Name
    FROM 
      Libraries 
      /* Join through your lookup table to match a book name to a library name */
      JOIN Lib_Book_LookUp ON Libraries.ID = Lib_Book_LookUp.libId
      JOIN Books ON Books.ID = Lib_Book_LookUp.bookId
    /* Which book to search for */
    WHERE Books.BookName = 'Fundamentals of calculus'
    

    The lookup table is appropriate because it allows you to normalize books down to a single record in the Books table if it exists in multiple libraries. As you have it, there is no real reason to have multiple copies in the Books table, and no reason for the Book ID column. In fact, the Book ID column as it is is quite misleading. There are books with two different titles having the same id 1.

    The Books table really ought to look like the following, with one record per book title (assuming title as the authority, forgetting about real authoritative things like ISBN)

    Books
    ID BookName
    1  Fundamentals of calculus
    2  Mechanics 
    3  Biology
    

    If you have multiple copies of each book possible at each library, you may consider normalizing the books per copy into a table that identifies them by library barcode. You would then match those ids to libraries as holdings:

    Books (defines bibliographic details)
    ID BookName
    1  Fundamentals of calculus
    2  Mechanics 
    3  Biology
    
    Book_Copies (Matches Books.ID to barcode, barcode is Primary Key)
    BookId Barcode
    1      1234567
    1      1234568
    2      8654321
    2      8654322
    
    Lib_Book_LookUp (matches book copies to libraries, allowing multiple copies by barcode)
    ID  libId bookBarcode
    1    1     1234567
    2    1     1234568
    3    2     8654321
    4    2     8654322
    

    To query, for example, the number of copies per book per library, you would use:

    SELECT 
      Libraries.Name,
      Books.BookName,
      COUNT(*)
    FROM 
      Libraries
      JOIN Lib_Book_LookUp ON Libraries.ID = Lib_Book_LookUp.libId
      JOIN Book_Copies ON Lib_Book_Lookup.bookBarcode = Book_Copies.Barcode
      JOIN Books ON Book_Copies.BookId = Books.ID
    GROUP BY 
      Libraries.Name, 
      Books.BookName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.