12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Retrieving Data With Queries-- this retrieves employees with managers with Ids between 122 and 125 inclusiveSELECT * FROM employees WHERE manager_id BETWEEN 122 AND 125;-- this uses the wildcard % to retrieve employee data-- where the last name contains mar somewhere in the nameSELECT employee_id, last_name FROM employees WHERE last_name LIKE '%mar%';-- this retrieves employees where the last name starts with MarSELECT employee_id, last_name FROM employees WHERE last_name LIKE 'Mar%';-- this retrieves employees where the commission percentage is not nullSELECT employee_id, last_name FROM employees WHERE commission_pct IS NOT NULL;-- the following retrieves data where the employee_id equals 125, 130, or 135SELECT employee_id, last_name, first_name FROM employeesWHERE employee_id IN (125, 130, 135);See Also:■ <strong>Oracle</strong> Database <strong>SQL</strong> Reference for detailed information on usingthe WHERE clause.6.2.5 Sorting Data Using the ORDER BY ClauseYou can use SELECT with the ORDER BY clause to retrieve and display rows from atable ordered (sorted) by a specified column in the table. The specified column in theORDER BY clause does not have to be in the select-list of columns that you want todisplay.You can specify the sort order ASC for ascending or DESC for descending. The defaultsort order is ascending, which means:■ Numeric values are displayed with the lowest values first, such as 1 to 999.■■Character values are displayed in alphabetical order, such as A first and Z last.Date values are displayed with the earliest value first, such as 01-JUN-93 before01-JUN-95.Null (empty) values are displayed last for ascending sequences and first fordescending sequences.Example 6–5 shows how to use SELECT with the ORDER BY clause to retrieve anddisplay rows from the employees table ordered (sorted) by specified columns.Example 6–5Using SELECT With ORDER BY-- the following retrieves rows with manager_id = 122 ordered by employee_id-- the order is the default ascending order, lowest employee_id displays firstSELECT * FROM employees WHERE manager_id = 122 ORDER BY employee_id;-- the following retrieves rows ordered by manager_id-- the order is specified as descending, highest manager_id displays firstSELECT employee_id, last_name, first_name, manager_id FROM employeesORDER BY manager_id DESC;See Example 6–20 on page 6-14 for the use of ORDER BY with the GROUP BY clause.<strong>SQL</strong>: Usage Information 6-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!