Java Reference
In-Depth Information
You can also specify into which columns to insert the data; this is useful if
you are not inserting data into each column of the new row. The following
INSERT statement does not insert a payRate for the new row:
INSERT INTO Employees (number, first, last) VALUES (102, 'Rich', 'Little')
In this case, the payRate column will assume a default value or be empty,
depending on the database.
Reading Data
The SELECT statement is used to retrieve data from a database. The syntax for
SELECT is:
SELECT column_name , column_name , ...
FROM table_name
WHERE conditions
The WHERE clause can use the comparison operators such as =, !=, <, >, <=,
and >=, as well as the BETWEEN and LIKE operators.
For example, the following statement selects the payRate, first and last
columns from the Employees table where the number column is 101:
SELECT first, last, payRate FROM Employees WHERE number = 101
To select all columns from a row, you can use the asterisk *:
SELECT * FROM Employees WHERE number = 101
The LIKE operator allows you to select entries containing a particular sub-
string. The following SELECT statement selects employee numbers whose last
name starts with an R:
SELECT number FROM Employees WHERE last LIKE 'R%'
Notice the percent symbol (%) is used to denote a wildcard in a LIKE oper-
ation. The following SELECT statement selects all employees whose last name
contains the pattern 'er' anywhere in their last name:
SELECT * FROM Employees WHERE last LIKE '%er%'
The AND and OR operators are used to combine WHERE expressions. The
following SELECT statement selects all employees whose pay is greater than
10.0 and less than or equal to 20.0:
SELECT * FROM Employees WHERE payRate > 10.0 AND payRate <= 20.0
Search WWH ::




Custom Search