Skip to content
Exercises · Q1

Q.Answer the following questions:

(a) Define RDBMS. Name any two RDBMS software.
(b) What is the purpose of the following clauses in a SELECT statement?
(i) ORDER BY
(ii) HAVING
(c) Cite any two differences between Single-row functions and Aggregate functions.
(d) What do you understand by Cartesian Product?
(e) Write the name of the functions to perform the following operations:
(i) To display the day like "Monday", "Tuesday", from the date when India got independence.
(ii) To display the specified number of characters from a particular position of a given string.
(iii) To display the name of the month in which you were born.
(iv) To display your name in capital letters.
Tamil Nadu DgeTextbookSubjective· 5mImportance★★★★★
38% · 15/40 Questions
✓ Free question

This solution defines RDBMS, explains the purpose of ORDER BY and HAVING clauses, differentiates between single-row and aggregate functions, clarifies the Cartesian Product, and identifies specific SQL functions for date and string manipulation.

(a) Define RDBMS. Name any two RDBMS software.

A Relational Database Management System (RDBMS) is a software system used to create, manage, and query relational databases. In an RDBMS, data is organized into tables, also known as relations, which consist of rows (records or tuples) and columns (attributes or fields). These tables are related to each other through common columns, typically using primary and foreign keys, which helps maintain data integrity and allows for efficient data retrieval and manipulation. RDBMS uses Structured Query Language (SQL) for managing and querying data.

Two common RDBMS software are:

  1. MySQL
  2. Oracle Database (Other examples include PostgreSQL, Microsoft SQL Server, SQLite)

(b) What is the purpose of the following clauses in a SELECT statement?

The SELECT statement is used to retrieve data from a database. Various clauses can be added to a SELECT statement to filter, group, and order the results.

(i) ORDER BY

The ORDER BY clause is used to sort the result set of a SELECT query. It arranges the rows in ascending (ASC) or descending (DESC) order based on the values in one or more specified columns. If no order is specified, ASC (ascending) is the default. This clause is typically placed after the FROM, WHERE, and GROUP BY clauses in a SELECT statement.

Example:

To sort employees by their salary in descending order:

SELECT EmpName, Salary
FROM Employees
ORDER BY Salary DESC;
(ii) HAVING

The HAVING clause is used to filter groups of rows based on a specified condition. Unlike the WHERE clause, which filters individual rows before they are grouped, the HAVING clause filters groups after they have been formed by the GROUP BY clause and after aggregate functions have been applied. It is used with aggregate functions (like SUM(), COUNT(), AVG(), MAX(), MIN()) to apply conditions to the results of these aggregations.

Example:

To display departments where the average salary is greater than 50000:

SELECT Department, AVG(Salary)
FROM Employees
GROUP BY Department
HAVING AVG(Salary) > 50000;
Important

The key difference between WHERE and HAVING is that WHERE filters individual rows before grouping, while HAVING filters groups after grouping and aggregation.

(c) Cite any two differences between Single-row functions and Aggregate functions.

SQL functions can be broadly categorized into single-row (or scalar) functions and aggregate (or group) functions.

Here are two key differences:

FeatureSingle-row FunctionsAggregate Functions
Input & OutputTake one row as input and return one value per row.Take a set of rows (a group) as input and return a single value for the entire group.
Usage with GROUP BYCan be used in SELECT, WHERE, ORDER BY clauses, and do not require a GROUP BY clause.Typically used with the GROUP BY clause to perform calculations on groups of rows. If GROUP BY is omitted, they operate on the entire result set as a single group.
ExamplesUPPER(), LOWER(), LENGTH(), SUBSTRING(), DAYNAME(), MONTHNAME(), NOW(), MOD()SUM(), COUNT(), AVG(), MAX(), MIN()

(d) What do you understand by Cartesian Product?

The Cartesian Product, also known as a cross join, is a relational algebra operation that combines every row from one table with every row from another table. If Table A has m rows and Table B has n rows, their Cartesian Product will result in a new table containing m * n rows. The number of columns in the resulting table will be the sum of the number of columns in Table A and Table B.

In SQL, a Cartesian Product occurs when you join two or more tables without specifying any join condition (i.e., without an ON clause for JOIN or a WHERE clause for implicit joins).

Example:

If TableA has 3 rows and TableB has 2 rows, their Cartesian Product will have 3×2=63 \times 2 = 6 rows.

SELECT *
FROM TableA, TableB;

or

SELECT *
FROM TableA CROSS JOIN TableB;
Watch out

A Cartesian Product often produces a very large and usually meaningless result set if it's not the intended operation. It's a common mistake when forgetting to specify a join condition between tables.

(e) Write the name of the functions to perform the following operations:

Assuming standard SQL functions commonly found in RDBMS like MySQL:

(i) To display the day like "Monday", "Tuesday", from the date when India got independence.
  • Function Name: DAYNAME()
  • Explanation: This function takes a date as input and returns the full name of the weekday (e.g., 'Monday', 'Tuesday').
  • Example Usage: DAYNAME('1947-08-15') would return 'Friday'.
(ii) To display the specified number of characters from a particular position of a given string.
  • Function Name: SUBSTRING() (or SUBSTR())
  • Explanation: This function extracts a substring of a specified length from a string, starting at a particular position.
  • Example Usage: SUBSTRING('Hello World', 7, 5) would return 'World'.
(iii) To display the name of the month in which you were born.
  • Function Name: MONTHNAME()
  • Explanation: This function takes a date as input and returns the full name of the month (e.g., 'January', 'February').
  • Example Usage: If you were born on '2005-03-10', MONTHNAME('2005-03-10') would return 'March'.
(iv) To display your name in capital letters.
  • Function Name: UPPER() (or UCASE())
  • Explanation: This function converts all characters in a given string to uppercase.
  • Example Usage: UPPER('john doe') would return 'JOHN DOE'.

✓Final answer

  1. RDBMS organizes data into related tables; MySQL and Oracle Database are two examples.
  2. ORDER BY sorts the result set; HAVING filters groups based on aggregate conditions.
  3. Single-row functions return one value per input row, while aggregate functions return one value per group of rows.
  4. Cartesian Product combines every row from one table with every row from another.
  5. (i) DAYNAME(), (ii) SUBSTRING(), (iii) MONTHNAME(), (iv) UPPER().

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.