0% found this document useful (0 votes)
23 views2 pages

Oracle SQL Basics for Infosys Training

This guide provides foundational Oracle SQL concepts for Infosys training, including basic syntax, SELECT and WHERE clauses, ORDER BY and DISTINCT, and GROUP BY and HAVING. It offers practical examples using Oracle's HR schema and includes practice questions for further learning. The document serves as a comprehensive resource for beginners to understand and apply SQL queries effectively.

Uploaded by

mahirajput1206
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Oracle SQL Basics for Infosys Training

This guide provides foundational Oracle SQL concepts for Infosys training, including basic syntax, SELECT and WHERE clauses, ORDER BY and DISTINCT, and GROUP BY and HAVING. It offers practical examples using Oracle's HR schema and includes practice questions for further learning. The document serves as a comprehensive resource for beginners to understand and apply SQL queries effectively.

Uploaded by

mahirajput1206
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Oracle SQL Basics - Infosys Training Preparation

This guide covers foundational Oracle SQL concepts used in Infosys Mysore training.

It includes examples from Oracle's official HR schema and basic query structures for practice.

1. Basic SQL Syntax


Every SQL statement follows this basic structure:

SELECT column_name(s)

FROM table_name

WHERE condition

ORDER BY column_name ASC|DESC;

2. SELECT and WHERE Clause


Example 1:

SELECT first_name, last_name, salary

FROM employees

WHERE salary > 5000;

Example 2:

SELECT first_name, department_id

FROM employees

WHERE department_id = 90;

3. ORDER BY and DISTINCT


Example 1: Sort employees by salary (descending)

SELECT first_name, salary

FROM employees

ORDER BY salary DESC;

Example 2: List unique job titles


SELECT DISTINCT job_id

FROM employees;

4. GROUP BY and HAVING


Example 1:

SELECT department_id, COUNT(*) AS total_employees

FROM employees

GROUP BY department_id;

Example 2:

SELECT department_id, AVG(salary) AS avg_salary

FROM employees

GROUP BY department_id

HAVING AVG(salary) > 8000;

5. Practice Questions (Infosys-style)


1. Display all employees whose salary is greater than 10000.

2. List the first name and department ID of employees in department 50.

3. Display unique job IDs from the EMPLOYEES table.

4. Show employees sorted by hire date (oldest first).

5. Display the total number of employees in each department.

6. Show the average salary for each department with more than 5 employees.

7. Find employees working as 'IT_PROG' and earning more than 6000.

8. Display all employee names where commission_pct is not null.

9. Retrieve the maximum and minimum salary from the EMPLOYEES table.

10. Display department IDs that have at least 3 employees.

Common questions

Powered by AI

The ORDER BY clause is used in SQL to sort the result set of a query by one or more columns, either in ascending (ASC) or descending (DESC) order. This is significant as it allows for data to be organized in a meaningful way for analysis or presentation. For example, using ORDER BY on a salary column can help prioritize the visualization of employees based on their earnings. In Source 1, an example is given where employees are sorted by their salary in descending order: SELECT first_name, salary FROM employees ORDER BY salary DESC .

Using aggregate functions like AVG and COUNT with GROUP BY in SQL is significant because it allows for summarizing data efficiently by breaking it into groups based on one or more columns. This helps in obtaining meaningful analytical insights, such as averages and totals per category. For example, in Source 1, GROUP BY is used along with COUNT to find the total number of employees in each department: SELECT department_id, COUNT(*) AS total_employees FROM employees GROUP BY department_id . These functions help derive actionable insights from complex datasets.

The DISTINCT keyword in a SQL query is used to remove duplicate values from a dataset, ensuring each returned result is unique. This is crucial in cases where you need to identify unique entries within a database, such as when determining unique job titles from a list of employees. For example, from Source 1, SELECT DISTINCT job_id FROM employees ensures that only unique job IDs are returned from the EMPLOYEES table, effectively removing any duplicates .

Using SQL queries to evaluate average salaries and employee counts per department provides insights into organizational structure and resource distribution. Such analyses help identify departments with potentially overpaid or underpaid employees, uncover workforce distribution across departments, and assess departmental cost efficiency. In Source 1, queries like SELECT department_id, AVG(salary) AS avg_salary FROM employees GROUP BY department_id and SELECT department_id, COUNT(*) AS total_employees FROM employees GROUP BY department_id help summarize vital HR metrics, thus aiding strategic management decisions and budget allocations .

The SELECT DISTINCT statement in SQL is used to return only distinct (unique) values from a result set, thereby eliminating duplicate entries. This is particularly useful when identifying unique entries within a dataset, such as determining all unique job titles within an employees database. It ensures efficiency by reducing redundancy and improving data integrity. For example, in Source 1, the statement SELECT DISTINCT job_id FROM employees is used to list unique job titles from the EMPLOYEES table .

GROUP BY and HAVING clauses are used in SQL to aggregate data and filter aggregated result sets based on conditions. GROUP BY groups rows that share a specified property so aggregate functions like COUNT, AVG, etc., can be applied. HAVING is used to filter such grouped data based on a condition, similar to WHERE but for aggregate data. For instance, in Source 1, GROUP BY is used to count employees per department, and HAVING is applied to filter departments with an average salary greater than 8000: SELECT department_id, AVG(salary) AS avg_salary FROM employees GROUP BY department_id HAVING AVG(salary) > 8000 .

The WHERE clause in SQL is crucial for filtering rows before any aggregations are performed, based on specified conditions. It directly impacts the efficiency and performance of the query by reducing data volume early. It is different from the HAVING clause, which filters data after aggregations like SUM or AVG are applied, essentially working with the result of GROUP BY. For example, in Source 1's query SELECT first_name, last_name, salary FROM employees WHERE salary > 5000, WHERE filters employees with a salary greater than 5000 before any further processing .

Practical exercises, such as Infosys-style questions, play a critical role in mastering SQL queries as they simulate real-world scenarios and data challenges. These exercises enforce understanding through application, requiring learners to synthesize their knowledge of syntax into actionable commands. They enhance problem-solving skills and ensure that learners can apply concepts like JOINS, GROUP BY, and sub-queries in practice scenarios. By addressing practical tasks like displaying employees with specific salaries or sorting data by hire date, individuals solidify their understanding of SQL commands and their implications .

SQL syntax and structure ensure effective data retrieval by providing clear, standardized commands to interact with databases. By using structured keywords and clauses like SELECT, WHERE, and ORDER BY, SQL allows complex queries to be broken down into understandable, modular segments that efficiently retrieve data. For instance, the basic SQL syntax includes steps: SELECT column_name(s), FROM table_name, WHERE condition, ORDER BY column_name ASC|DESC, enabling precise data selection, sorting, and presentation . This systemized approach ensures logical ordering and execution of database operations, enhancing both performance and reliability.

Practice questions using the HAVING clause deepen SQL understanding by challenging learners to consider data after aggregation. Unlike the WHERE clause, which filters rows before aggregation, HAVING applies conditions on grouped results, thus requiring a deeper comprehension of SQL logic and sequence in query execution. For instance, understanding the need to filter groups by the average salary using HAVING — as in SELECT department_id, AVG(salary) AS avg_salary FROM employees GROUP BY department_id HAVING AVG(salary) > 8000 —develops advanced data manipulation skills, distinguishing group-level filtering from individual row conditions .

You might also like