Hjælp til select
Hej eksperterEr der en, der kan (og vil) lave en select for mig? Og ja jeg ved godt, jeg skal sætte mig ind i det, men... Lige nu skal jeg bare bruge selecten til at teste relationerne i databasen.
Ud fra nedenstående tabeller (med lidt data), vil jeg gerne lave en select, der viser alle book.title where borrower.name = 'John'.
Min søn skal til eksamen i morgen, så han er lidt presset på tid og... Joins er ikke en del af pensum. Håber der er en af jer, der vil hjælpe :)
CREATE TABLE book
(
isbn varchar (100) not null,
title varchar (100),
type varchar (100),
category varchar (100),
primary key (isbn)
);
CREATE TABLE location
(
locid MEDIUMINT NOT NULL AUTO_INCREMENT,
location varchar (100),
primary key (locid)
);
CREATE TABLE borrower
(
ssn varchar (9) not null,
name varchar (100),
address varchar (100),
phonenr varchar (100),
email varchar (100),
primary key (ssn)
);
CREATE TABLE author
(
anum MEDIUMINT NOT NULL AUTO_INCREMENT,
name varchar (100),
primary key (anum)
);
CREATE TABLE author_book
(
anum mediumint,
isbn varchar (100),
primary key (anum, isbn),
foreign key (isbn) references book(isbn),
foreign key (anum) references author(anum)
);
CREATE TABLE copy
(
copynum integer not null,
locid mediumint,
isbn varchar (100),
primary key (copynum, locid, isbn),
foreign key (locid) references location(locid),
foreign key (isbn) references book(isbn)
);
CREATE TABLE transaction
(
transid MEDIUMINT NOT NULL AUTO_INCREMENT,
ssn varchar (9),
copynum integer,
locid mediumint,
isbn varchar (100),
lendingdate date,
returndate date,
primary key (transid),
foreign key (ssn) references borrower(ssn),
foreign key (copynum, locid, isbn) references copy(copynum, locid, isbn)
);
INSERT INTO book VALUES
('0-07-295886-3', 'Database system concepts', 'specialist literature', null),
('978-0131873254', 'Database systems: the complete book', 'specialist literature', null);
INSERT INTO `location`(`location`) VALUES
('681.3.07'),
('681.3.08'),
('681.3.09');
INSERT INTO `author`(`name`) VALUES ('Abraham Silberschatz'),
('Henry F. Korth'), ('S. Sudarshan'), ('Hector Garcia-Molina'),
('Jeffrey D. Ullman'), ('Jennifer Widom');
INSERT INTO `author_book` (`anum`, `isbn`) VALUES
('1', '0-07-295886-3'),
('2', '0-07-295886-3'),
('3', '0-07-295886-3'),
('4', '978-0131873254'),
('5', '978-0131873254'),
('6', '978-0131873254');
INSERT INTO `copy`(`copynum`,`locid`, `isbn`) VALUES
('1', '1', '0-07-295886-3'),
('2', '1', '0-07-295886-3'),
('1', '1', '978-0131873254'),
('2', '2', '978-0131873254'),
('3', '3', '978-0131873254');
INSERT INTO borrower VALUES
('123456789', 'John', 'Main Street 3', '456-54321', 'john@somewhere.com'),
('987654321', 'Joe', 'Railroad 24', '123-98765', 'joe@the.plummer');
INSERT INTO `transaction`(`ssn`, `copynum`, `locid`, `isbn`, `lendingdate`, `returndate`)
VALUES
('123456789', '1', '1', '0-07-295886-3', '2008-10-21', '2008-11-21'),
('987654321', '3', '3', '978-0131873254', '2008-10-25', '2008-11-25');