- What is a JOIN?
A JOIN combines rows from multiple tables. - What is INNER JOIN?
Returns matching rows from both tables. - What is LEFT JOIN?
Returns all rows from left table and matching rows from right. - What is RIGHT JOIN?
Returns all rows from right table and matching rows from left. - What is FULL OUTER JOIN?
Returns all matching and non-matching rows from both tables. - What is CROSS JOIN?
Returns Cartesian product of both tables. - What is SELF JOIN?
A table joined with itself. - Difference between INNER and LEFT JOIN?
INNER returns matches only; LEFT returns all left rows. - What happens if no match in LEFT JOIN?
NULL values are returned for right table columns. - What is Cartesian product?
Every row from first table joins with every row from second. - Can we join more than 2 tables?
Yes, multiple joins are allowed. - Which join is used to find unmatched records?
LEFT JOIN withWHERE right_table.id IS NULL. - Scenario: Find customers with no orders.
Use LEFT JOIN between customers and orders, filter NULL orders. - Scenario: Get employee with manager name.
Use SELF JOIN on employee table. - Can we join tables without primary key?
Yes, using common columns.
A blog about basic database questions. It has all the important database terms and their simple explanation, easy to remember. Most of the database terms asked in the interviews like what is DBMS, what is Tuple in database , Data Modelling.
Thursday, May 14, 2026
Joins (36–50)
Wednesday, May 13, 2026
Filtering & Sorting (21–35)
- What does WHERE clause do?
It filters rows based on conditions. -
Difference between WHERE and HAVING?
WHERE filters rows before grouping; HAVING filters groups after aggregation. -
What is ORDER BY?
It sorts query results in ascending or descending order. -
Default sort order in SQL?
Ascending (ASC) by default. -
What is DISTINCT?
It removes duplicate values from result. -
How do you fetch top 5 records?
SELECT TOP 5 * FROM table;(SQL Server) -
How do you fetch first 5 rows in MySQL?
SELECT * FROM table LIMIT 5; -
What is BETWEEN?
It filters values within a range. -
What is IN operator?
It matches values from a given list. -
What is LIKE used for?
It is used for pattern matching. -
What does
%mean in LIKE?
It matches zero or more characters. -
What does
_mean in LIKE?
It matches exactly one character. -
How do you handle NULL values?
UseIS NULLorIS NOT NULL. -
Can we use = NULL?
No, useIS NULL. -
What is alias in SQL?
A temporary name given to a column or table.
Monday, September 11, 2023
OLTP vs. OLAP Databases
OLTP (Online Transaction Processing) and OLAP (Online Analytical Processing) are two distinct types of database systems designed to serve different purposes in an organization. Here are the key differences between OLTP and OLAP databases:
1. Purpose:
·
OLTP:
OLTP databases are designed for transactional processing. They handle
day-to-day operational data, such as order processing, inventory management,
and customer interactions. The primary goal is to support real-time
transactional activities and ensure data accuracy.
·
OLAP:
OLAP databases are designed for analytical processing. They store historical
data, often in large volumes, and support complex queries for reporting, data
analysis, and decision-making. OLAP databases focus on providing insights from
data rather than handling individual transactions.
2. Data Structure:
·
OLTP:
OLTP databases have a normalized data structure, which minimizes data
redundancy. They use many small, related tables and enforce referential
integrity through primary keys and foreign keys.
·
OLAP:
OLAP databases typically use a denormalized or star/snowflake schema structure.
Data is aggregated, and dimensional modeling is often employed to facilitate
complex queries and reporting.
3. Query Complexity:
·
OLTP:
OLTP queries are relatively simple and usually involve basic CRUD (Create,
Read, Update, Delete) operations. The focus is on fast and efficient retrieval
and modification of individual records.
·
OLAP:
OLAP queries are complex and involve aggregations, joins, and multidimensional
analysis. These queries are optimized for reporting and data analysis, and
response times can be longer compared to OLTP systems.
4. Data Volume:
·
OLTP:
OLTP databases handle a moderate volume of data, typically focused on current
and recent transactions. They prioritize fast write operations and are
optimized for low-latency access.
·
OLAP:
OLAP databases store a large volume of historical data, often including years
of data for analytical purposes. They prioritize read-heavy operations for
complex reporting and analysis.
5. User Types:
·
OLTP:
OLTP systems primarily serve operational users who interact with the system in
real-time, such as customer service representatives, sales teams, and order
processing personnel.
·
OLAP:
OLAP systems cater to analytical users, including business analysts, data
scientists, and decision-makers, who require in-depth data analysis, ad-hoc
querying, and reporting capabilities.
6. Data Freshness:
·
OLTP:
Data in OLTP databases is typically up-to-date in real-time, reflecting the
current state of the business operations.
·
OLAP:
OLAP databases may have a slight delay in data updates due to the process of
aggregating and loading large volumes of historical data.
7. Indexing:
·
OLTP:
OLTP databases use minimal indexing to optimize write operations and maintain
data integrity.
·
OLAP:
OLAP databases use extensive indexing and pre-aggregated data to optimize
read-heavy analytical queries.
8. Examples:
·
OLTP:
Examples of OLTP systems include e-commerce platforms, banking systems, and
airline reservation systems.
·
OLAP:
Examples of OLAP systems include data warehouses, business intelligence
platforms, and reporting systems.
In summary, OLTP
databases focus on real-time transactional processing with normalized data structures,
while OLAP databases are designed for analytical processing, historical data
storage, and complex reporting with denormalized structures. These differences
reflect the distinct roles