
User's Guide
Part II. Tutorials
Chapter 7. Selecting Data from Database Tables
Selecting rows from a table
Sometimes you will not want to see information on all the employees in the employee table. Adding a WHERE clause to the SELECT statement allows only some rows to be selected from a table.
For example, suppose you would like to look at the employees with first name John.
List all employees named John:
emp_id |
manager_id |
emp_fname |
emp_lname |
dept_id |
318 |
1576 |
John |
Crow |
400 |
862 |
501 |
John |
Sheffield |
100 |
1483 |
1293 |
John |
Letiecq |
300 |
Apostrophes and case-sensitivity
- The apostrophes (single quotes) around the name 'John' are required. They indicate that John is a character string. Quotation marks (double quotes) have a different meaning. Quotation marks can be used to make otherwise invalid strings valid for column names and other identifiers.
- The sample database provided with SQL Anywhere is not case sensitive, so you would get the same results whether you searched for ' 'JOHN', 'john', or 'John'.
Again, you can combine what you have learned:
SELECT emp_fname, emp_lname, birth_date
FROM employee
WHERE emp_fname = 'John'
ORDER BY birth_date
Notes
- How you order clauses is important. The FROM clause comes first, followed by the WHERE clause, and then the ORDER BY clause. If you type the clauses in a different order, you will get a syntax error.
- You do not need to split the statement into several lines. You can enter the statement into the command window in any format. If you use more than the number of lines that fit on the screen, the text scrolls in the Command window.
