php_mysql_apache [Electronic resources]

Julie C. Meloni

نسخه متنی -صفحه : 323/ 166
نمايش فراداده

Workshop

The workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.

Quiz

1:

The integer 56678685 could be which datatype(s)?

2:

How would you define a field that could only contain the following strings: apple, pear, banana, cherry?

3:

What would be the LIMIT clauses for selecting the first 25 records of a table? Then the next 25?

4:

How would you formulate a string comparison using LIKE to match first names of "John" or "Joseph"?

5:

How would you explicitly refer to a field called id in a table called table1?

6:

Write a SQL statement that joins two tables, orders, and items_ordered, with a primary key in each of order_id. From the orders table, select the following fields: order_name and order_date. From the items_ordered table, select the item_description field.

7:

Write a SQL query to find the starting position of a substring "grape" in a string "applepearbananagrape".

8:

Write a query that selects the last five characters from the string "applepearbananagrape".

Answers

A1:

MEDIUMINT, INT, or BIGINT.

A2:

ENUM ('apple', 'pear', 'banana', 'cherry') or SET ('apple', 'pear', 'banana', 'cherry')

A3:

LIMIT 0, 25 and LIMIT 25, 25

A4:

LIKE 'Jo%'

A5:

Use table1.id instead of id in your query.

A6:

SELECT orders.order_name, orders.order_date, items_ordered.item_description FROM orders LEFT JOIN items_ordered ON orders.order_id = items_ordered.id;

A7:

SELECT LOCATE('grape', 'applepearbananagrape');

A8:

SELECT RIGHT("applepearbananagrape", 5);

Activity

Q1:

Take the time to create some sample tables, and practice using basic INSERT and SELECT commands.