1 select authorid, lastname from authors output: exercise authoridfirstnamelastname 1harveydeitel...
TRANSCRIPT
1
SELECT authorID, lastName FROM authors
OUTPUT:
Exercise
AuthorID FirstName LastName
1 Harvey Deitel
2 Paul Deitel
3 Andrew Goldberg
4 David Choffnes
2
SELECT title, editionNumber, copyright
FROM titles
WHERE copyright > '2005'
OUTPUT:
ISBN Title EditionNumber Copyright
0131450913
Internet & World Wide Web How to Program
3 2004
0131525239Visual C# 2005 How to Program
2 2006
0131828274 Operating Systems 3 2004
0131857576 C++ How to Program 5 2005
0131869000Visual Basic 2005 How to Program
3 2006
0132222205 Java How to Program 7 2007
0132404168 C How to Program 5 2007
3
OUTPUT:
SELECT authorID, firstName, lastName
FROM authors
WHERE lastName LIKE 'D%'
authorID firstName lastName
1 Harvey Deitel
2 Paul Deitel
4
SELECT authorID, firstName, lastName
FROM authors
WHERE lastName LIKE '_o%'
OUTPUT:
authorID firstName lastName
3 Andrew Goldberg
5
SELECT authorID, firstName, lastName
FROM authors
ORDER BY lastName ASC
OUTPUT: authorID firstName lastName
4 David Choffnes
1 Harvey Deitel
2 Paul Deitel
3 Andrew Goldberg
6
SELECT authorID, firstName, lastName
FROM authors
ORDER BY lastName DESC
OUTPUT: authorID firstName lastName
3 Andrew Goldberg
1 Harvey Deitel
2 Paul Deitel
4 David Choffnes
7
SELECT authorID, firstName, lastName
FROM authors
ORDER BY lastName, firstName
OUTPUT:
authorID firstName lastName
4 David Choffnes
1 Harvey Deitel
2 Paul Deitel
3 Andrew Goldberg
8
SELECT isbn, title, editionNumber, copyright
FROM titles
WHERE title LIKE '%How to Program'
ORDER BY title ASC
OUTPUT: isbn title editionNumbe
r copyright
0132404168 C How to Program 5 2007
0131857576 C++ How to Program 5 2005
0131450913
Internet & World Wide Web How to Program
3 2004
0132222205 Java How to Program 7 2007
0131869000Visual Basic 2005 How to Program
3 2006
0131525239Visual C# 2005 How to Program
2 2006
9SELECT firstName, lastName, isbn
FROM authors
INNER JOIN authorISBN
ON authors.authorID = authorISBN.authorID
ORDER BY lastName, firstName
OUTPUT: firstName lastName isbn
David Choffnes 0131828274
Harvey Deitel 0131450913
Harvey Deitel 0131525239
Harvey Deitel 0131828274
Harvey Deitel 0131857576
Harvey Deitel 0131869000
Harvey Deitel 0132222205
Harvey Deitel 0132404168
Paul Deitel 0131450913
Paul Deitel 0131525239
Paul Deitel 0131828274
Paul Deitel 0131857576
Paul Deitel 0131869000
Paul Deitel 0132222205
Paul Deitel 0132404168
Andrew Goldberg 0131450913
10
INSERT INTO authors ( firstName, lastName )
VALUES ( 'Sue', 'Smith' )
OUTPUT:
11
UPDATE authors
SET lastName = 'Jones'
WHERE lastName = 'Smith' AND firstName = 'Sue'
OUTPUT:
12
DELETE FROM authors
WHERE lastName = 'Jones' AND firstName = 'Sue'
OUTPUT:
Write SQL queries for the books database that perform each of the following tasks:
a) Select all authors from the Authors table with the columns in the order lastName, firstName and authorID.
b) Select a specific author and list all books for that author. Include the title, year and ISBN number. Order the information alphabetically by title.
c) Add a new author to the Authors table.
d) Add a new title for an author (remember that the book must have an entry in the AuthorISBN table).
Correct each of the following SQL statements that refer to the books database.
a) SELECT FROM author FIELD firstName WHERE authorID = 3
b) SELECT isbn, title FROM Titles ORDER WITH title DESC
c) INSERT Authors ( authorID, firstName, lastName )VALUES ( "2", "Jane", "Doe" )