viperfx07 is here to blog about hacking, cracking, website, application, android, and many more.

Tuesday, October 5, 2010

Week 9 Practice: Database

1:33 PM Posted by viperfx07 No comments
This week's challenge is not so hard, just basic queries that we might use on our project.

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