The challenge:
1. Use the INSERT command to create a couple of new books in the table
2. Use the SELECT command to find all books whose title begins with W
3. Use the SELECT command to find all books whose price is less than 10
4. Use a LIMIT clause on a SELECT command to just list the first two books
5. Use both LIMIT and ORDER BY in a SELECT command- which one happens
first? (hint: use ORDER BY bookid LIMIT 2)
If you wanna try the query, just go to http://www.w3schools.com/sql/sql_tryit.asp. Note: LIMIT clause doesn't exist on the website
The answer:
1. For number 1, you can copy and then modify the value of the following query.
INSERT INTO books (title, author, isbn, cost)
VALUES ('Managing Enterprise Content', 'Barry Liu', 363562425127189, 57)
2. SELECT * FROM books WHERE title LIKE 'W%'
3. SELECT * FROM books WHERE cost<10
4. SELECT * FROM books LIMIT 0,2 or SELECT * FROM books LIMIT 2
note: 0 means the starting row (the row starts with 0). 2 means how many records we want to
get from the starting row.
5. SELECT * FROM books ORDER BY bookid LIMIT 2.
The query shows the first 2 records of books table after it's sorted by its bookid,
0 comments:
Post a Comment