FOR SQL with the following data: CREATE TABLE books ( books_id INT PRIMARY KEY A
ID: 3735875 • Letter: F
Question
FOR SQL with the following data:
CREATE TABLE books (
books_id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(1000),
isbn VARCHAR(100),
num_pages INT
);
CREATE TABLE borrower (
borrower_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(100),
last_name VARCHAR(100),
lib_card INT
);
INSERT INTO books
VALUES (1,'The Way of Shadows','0-316-03367-7',688);
INSERT INTO books
VALUES (2,'The Parafaith War','0-8125-3894-3',480);
INSERT INTO books
VALUES (3,'The Book Thief','033036426X',584);
INSERT INTO books
VALUES (4,'Me Talk Pretty One Day','0-316-77772-2',288);
INSERT INTO books
VALUES (5,'Warbreaker','978-0-7653-2030-8',592);
INSERT INTO books
VALUES (6,NULL,'','');
INSERT INTO borrower
VALUES (1,'Trisana','Chandler',1112223334);
INSERT INTO borrower
VALUES (2,'Shallan','Walker',9998887776);
INSERT INTO borrower
VALUES (3,'Annie','Wilkes',5554446660);
INSERT INTO borrower
VALUES (4,'','','');
Write a query to display the borrower name and title for all books checked out by the borrower who currently has the most books?
Explanation / Answer
Add one more column 'Books_id' to borrower table to find out the foriegn key relationship.
And the query is :
ALTER TABLE borrower ADD COLUMN Books_id INT;
INSERT INTO borrower
VALUES (1,'Trisana','Chandler',1112223334, 3);
SELECT concat(br.first_name,br.last_name),b.title from BOOKS b, BORROWER br where br.books_id = b.books_id ;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.