Course Title: DataBase
Date: 10-Feb-2015
SELECT STATEMENT
Retrieve Data
1. SELECT * FROM employees;
2. SELECT last_name FROM employees;
3. SELECT employee_id,first_name,last_name FROM employees;
4. SELECT last_name, salary, salary + 1000 FROM employees;
CONCATENATION
Combine Data
1. SELECT first_name,last_name FROM employees;
2. SELECT first_name||last_name FROM employees;
3. SELECT first_name||' '||last_name FROM employees;
-- The Employee id of Mr. Douglas Grant is 199
4. SELECT 'The employee id of Mr.' ||first_name||' '||last_name||' is '||employee_id FROM employees;
5. SELECT 'The employee id of Mr.' ||first_name||' '||last_name||' is '||employee_id AS "Detail" FROM employees;
DISTINCT
No Duplicate Data
1. SELECT job_id FROM job_history;
2. SELECT DISTINCT job_id FROM job_history;
WHERE
Filter Records
1. SELECT * FROM EMP_DETAILS_VIEW where city='Seattle'
2. SELECT * FROM EMP_DETAILS_VIEW where department_id=90
3. SELECT * FROM EMP_DETAILS_VIEW where salary>=17000
SQL AND & OR Operators Combining AND & OR
Filter Records Based On More Than One Condition
1. SELECT * FROM LOCATIONS WHERE Country_id='UK' AND City='Oxford';
2. SELECT * FROM LOCATIONS WHERE Country_id='UK' OR City='Oxford';
3. SELECT * FROM LOCATIONS WHERE Country_id='UK' AND (City='London' OR City='Oxford');
ORDER BY
Sort The Result-Set
1. SELECT * FROM LOCATIONS Order By COUNTRY_ID;
2. SELECT * FROM LOCATIONS Order By COUNTRY_ID DESC;
3. SELECT Country_Id,CITY FROM LOCATIONS Order By Country_Id,CITY ;
BETWEEN
Select Values Within A Range
1. SELECT * FROM JOBS where MAX_SALARY Between 30000 and 40000
2. select * from JOBS where MAX_SALARY not Between 30000 and 40000
3. select * from JOB_HISTORY where START_DATE between '13-JAN-01' AND '28-OCT-01';