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

  • SEARCH
  • Home
  • 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 8796889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:43:33+00:00 2026-06-13T23:43:33+00:00

So here are three relations: Table Members Members(member_id, name, city, state) where member_id is

  • 0

So here are three relations:

Table Members

Members(member_id, name, city, state)

where member_id is the primary key

Table Borrowed

Borrowed(borrow_id, lib_id, member_id)

where borrow_id is the primary key

Table Libraries

Libraries(lib_id, lib_address, lib_city, lib_state)

where lib_id is the primary key

Both lib_id and member_id are foreign keys

So I am trying to write a query that finds all of the member_id of members that have borrowed a book at EVERY library in their city. This means that

members.city = libraries.lib_city AND members.state = libraries.lib_state

I was thinking about using relational division. For example you have a relation consisting of the member_id’s and all of the lib_id where they have borrowed a book. And you divide this by a relation that consists of all of the lib_id in that member’s city.

However, I am confused as to how to write this in relational algebraic terms.

In mysql/sql it is very easy but the translation to relational algebra is where I get stuck.

  • 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-13T23:43:34+00:00Added an answer on June 13, 2026 at 11:43 pm

    One strategy is to match the COUNT(DISTINCT lib_id) per member_id with the total COUNT(DISTINCT lib_id) per city. If the two are equal, the individual has borrowed from every library in his city.

    I think the following will do the job:

    SELECT 
      member_id, 
      /* Total libraries borrowed from by member */
      COUNT(DISTINCT Borrowed.lib_id) AS num_libs_borrowed,
      /* Total libs in the member's city */
      COUNT(DISTINCT Libraries.lib_id) AS total_city_libs
    FROM 
      Members
      /* JOIN the city between Members & Libraries */
      JOIN Libraries ON Members.city = Libraries.lib_city
      /* JOIN member to borrowed */
      JOIN Borrowed ON Members.member_id = Borrowed.member_id
    GROUP BY member_id 
    /* If the number of libs borrowed from = the total libs in the city... */
    HAVING num_libs_borrowed = total_city_libs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a three SQL tables: create table users ( id serial primary key,
I have a table with three fields, FirstName, LastName and Email. Here's some dummy
I am having three arraylist,Here I have to concatenate 2 arraylist and display it
This is a continuation of this question from yesterday . Here are my three
Here are the constraints I have three buckets (water) capacities 10 litre, 2 liters
Here's my scenario: I need to make three or four calls to different WCF
I have three tables: Employee(EmployeeID,Fname,Lname...) ProjectHeader(ProjectID,LeadID,Status....) ProjectDetails(ProjectDetailsID,ProjectID....) Here's my current code: $get_projects = SELECT
Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on
okey so here is my structure. one.php two.php three.php one.php includes both two.php and
Rails noob here. I have a rails application with (in this example) three tables.

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.