Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exercise SELECT authorID, lastName FROM authors AuthorID FirstName

Similar presentations


Presentation on theme: "Exercise SELECT authorID, lastName FROM authors AuthorID FirstName"— Presentation transcript:

1 Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
1 Exercise SELECT authorID, lastName FROM authors OUTPUT: AuthorID FirstName LastName 1 Harvey Deitel 2 Paul 3 Andrew Goldberg 4 David Choffnes 1

2 SELECT title, editionNumber, copyright FROM titles
2 SELECT title, editionNumber, copyright FROM titles WHERE copyright > '2005' ISBN Title EditionNumber Copyright Internet & World Wide Web How to Program 3 2004 Visual C# 2005 How to Program 2 2006 Operating Systems C++ How to Program 5 2005 Visual Basic 2005 How to Program Java How to Program 7 2007 C How to Program OUTPUT: 2

3 SELECT authorID, firstName, lastName FROM authors
3 SELECT authorID, firstName, lastName FROM authors WHERE lastName LIKE 'D%' OUTPUT: authorID firstName lastName 1 Harvey Deitel 2 Paul 3

4 SELECT authorID, firstName, lastName FROM authors
4 SELECT authorID, firstName, lastName FROM authors WHERE lastName LIKE '_o%' OUTPUT: authorID firstName lastName 3 Andrew Goldberg 4

5 SELECT authorID, firstName, lastName FROM authors
5 SELECT authorID, firstName, lastName FROM authors ORDER BY lastName ASC OUTPUT: authorID firstName lastName 4 David Choffnes 1 Harvey Deitel 2 Paul 3 Andrew Goldberg 5

6 SELECT authorID, firstName, lastName FROM authors
6 SELECT authorID, firstName, lastName FROM authors ORDER BY lastName DESC OUTPUT: authorID firstName lastName 3 Andrew Goldberg 1 Harvey Deitel 2 Paul 4 David Choffnes 6

7 SELECT authorID, firstName, lastName FROM authors
7 SELECT authorID, firstName, lastName FROM authors ORDER BY lastName, firstName OUTPUT: authorID firstName lastName 4 David Choffnes 1 Harvey Deitel 2 Paul 3 Andrew Goldberg 7

8 SELECT isbn, title, editionNumber, copyright FROM titles
8 SELECT isbn, title, editionNumber, copyright FROM titles WHERE title LIKE '%How to Program' ORDER BY title ASC isbn title editionNumber copyright C How to Program 5 2007 C++ How to Program 2005 Internet & World Wide Web How to Program 3 2004 Java How to Program 7 Visual Basic 2005 How to Program 2006 Visual C# 2005 How to Program 2 OUTPUT: 8

9 SELECT firstName, lastName, isbn FROM authors INNER JOIN authorISBN
ON authors.authorID = authorISBN.authorID ORDER BY lastName, firstName 9 OUTPUT: firstName lastName isbn David Choffnes Harvey Deitel Paul Andrew Goldberg 9

10 INSERT INTO authors ( firstName, lastName ) VALUES ( 'Sue', 'Smith' )
10 INSERT INTO authors ( firstName, lastName ) VALUES ( 'Sue', 'Smith' ) OUTPUT: 10

11 WHERE lastName = 'Smith' AND firstName = 'Sue'
11 UPDATE authors SET lastName = 'Jones' WHERE lastName = 'Smith' AND firstName = 'Sue' OUTPUT: 11

12 WHERE lastName = 'Jones' AND firstName = 'Sue'
12 DELETE FROM authors WHERE lastName = 'Jones' AND firstName = 'Sue' OUTPUT: 12

13 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).

14 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" )


Download ppt "Exercise SELECT authorID, lastName FROM authors AuthorID FirstName"

Similar presentations


Ads by Google