0% found this document useful (0 votes)
2 views

Hour_2_SQL_Basics_Practice

The document provides an overview of SQL basics, including the SELECT statement, filtering data with the WHERE clause, and limiting results using FETCH FIRST. It includes syntax and multiple examples for each topic to illustrate their usage. Additionally, there are sections for practice to reinforce the concepts learned.

Uploaded by

Satya sv
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Hour_2_SQL_Basics_Practice

The document provides an overview of SQL basics, including the SELECT statement, filtering data with the WHERE clause, and limiting results using FETCH FIRST. It includes syntax and multiple examples for each topic to illustrate their usage. Additionally, there are sections for practice to reinforce the concepts learned.

Uploaded by

Satya sv
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Hour 2: SQL Basics - Practice Examples

1. SELECT Statement
Syntax: SELECT column1, column2 FROM table_name;
Examples:
1. SELECT first_name, last_name FROM employees;
2. SELECT department_id FROM departments;
3. SELECT * FROM employees;
4. SELECT salary FROM employees;
5. SELECT first_name || ' ' || last_name AS full_name FROM employees;
6. SELECT DISTINCT job_id FROM employees;
7. SELECT COUNT(*) FROM employees;
8. SELECT first_name, salary * 12 AS annual_salary FROM employees;
9. SELECT SYSDATE FROM dual;
10. SELECT 'Hello, Oracle SQL!' FROM dual;

[ Practice Here: _______________________________________ ]

2. Filtering Data with WHERE


Syntax: SELECT column1 FROM table_name WHERE condition;
Examples:
1. SELECT * FROM employees WHERE salary > 50000;
2. SELECT first_name, last_name FROM employees WHERE department_id = 10;
3. SELECT * FROM employees WHERE hire_date >= '01-JAN-2020';
4. SELECT * FROM employees WHERE job_id = 'IT_PROG';
5. SELECT * FROM employees WHERE salary BETWEEN 40000 AND 60000;
6. SELECT * FROM employees WHERE last_name LIKE 'A%';
7. SELECT * FROM employees WHERE department_id IN (10, 20, 30);
8. SELECT * FROM employees WHERE manager_id IS NULL;
9. SELECT * FROM employees WHERE job_id != 'SA_REP';
10. SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

[ Practice Here: _______________________________________ ]

3. Limiting Results (FETCH FIRST)


Syntax: SELECT * FROM table_name FETCH FIRST n ROWS ONLY;
Examples:
1. SELECT * FROM employees FETCH FIRST 5 ROWS ONLY;
2. SELECT * FROM employees ORDER BY hire_date FETCH FIRST 10 ROWS ONLY;
3. SELECT first_name, salary FROM employees FETCH FIRST 3 ROWS ONLY;
4. SELECT department_id FROM departments FETCH FIRST 2 ROWS ONLY;
5. SELECT job_id FROM employees ORDER BY salary DESC FETCH FIRST 1 ROW ONLY;
6. SELECT DISTINCT department_id FROM employees FETCH FIRST 4 ROWS ONLY;
7. SELECT * FROM employees WHERE salary > 50000 FETCH FIRST 7 ROWS ONLY;
8. SELECT * FROM employees ORDER BY last_name ASC FETCH FIRST 8 ROWS ONLY;
9. SELECT job_id, COUNT(*) FROM employees GROUP BY job_id FETCH FIRST 5 ROWS
ONLY;
10. SELECT department_id, AVG(salary) FROM employees GROUP BY department_id
FETCH FIRST 6 ROWS ONLY;

[ Practice Here: _______________________________________ ]

You might also like