User Guide

Table Of Contents
Using SQL 453
Tip: If you are using Macromedia Dreamweaver MX 2004 or Macromedia HomeSite+, you can use
the built-in query builder to build SQL statements graphically by selecting the tables and records to
retrieve. For more information, see Writing queries using an editor” on page 460.
In many cases, you do not want all rows from a table, but only a subset of rows. The next example
returns all rows from the employees table, where the value of the DeptID column for the row is 3:
SELECT * FROM employees WHERE DeptID=3
You interpret this statement as "Select all rows from the table employees where the DeptID is 3".
SQL also lets you specify the table columns to return. For example, instead of returning all
columns in the table, you can return a subset of columns:
SELECT LastName, FirstName FROM employees WHERE DeptID=3
You interpret this statement as "Select the columns FirstName and LastName from the table
employees where the DeptID is 3".
In addition to with reading data from a table, you can write data to a table using the SQL
INSERT statement. The following statement adds a new row to the employees table:
INSERT INTO employees(EmpID, LastName, Firstname)
VALUES(51, 'Doe', 'John')
Basic SQL syntax elements
The following sections briefly describe the main SQL command elements.
Statements
A SQL statement always begins with a SQL verb. The following keywords identify commonly
used SQL verbs:
Statement clauses
Use the following keywords to refine SQL statements:
Keyword Description
SELECT Retrieves the specified records.
INSERT Adds a new row.
UPDATE Changes values in the specified rows.
DELETE Removes the specified rows.
Keyword Description
FROM Names the data tables for the operation.
WHERE Sets one or more conditions for the operation.
ORDER BY Sorts the result set in the specified order.
GROUP BY Groups the result set by the specified select list items.