SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM Computer Scientists in the 1970s. By executing queries, SQL can create, update, delete, and retrieve data in databases like MySQL, Oracle, PostgreSQL, etc. Overall, SQL is a query language that communicates with databases.
In this article, we cover 70+ SQL Interview Questions with answers asked in SQL developer interviews at MAANG and other high-paying companies. Whether you are a fresher or an experienced professional with 2, 5, or 10 years of experience, this article gives you all the confidence you need to ace your next SQL interview.

SQL Interview Questions and Answers for Freshers
1. What is SQL?Â
SQL stands for Structured Query Language. It is a language used to interact with the database, i.e to create a database, to create a table in the database, to retrieve data or update a table in the database, etc. SQL is an ANSI(American National Standards Institute) standard. Using SQL, we can do many things. For example – we can execute queries, we can insert records into a table, can update records, can create a database, can create a table, can delete a table, etc.
2. What is a database?Â
A Database is defined as a structured form of data storage in a computer or a collection of data in an organized manner and can be accessed in various ways. It is also the collection of schemas, tables, queries, views, etc. Databases help us with easily storing, accessing, and manipulating data held on a computer. The Database Management System allows a user to interact with the database.
3. Does SQL support programming language features?Â
It is true that SQL is a language, but it does not support programming as it is not a programming language, it is a command language. We do not have conditional statements in SQL like for loops or if..else, we only have commands which we can use to query, update, delete, etc. data in the database. SQL allows us to manipulate data in a database.
4. What is the difference between CHAR and VARCHAR2 datatype in SQL?Â
Both of these data types are used for characters, but varchar2 is used for character strings of variable length, whereas char is used for character strings of fixed length. For example, if we specify the type as char(5) then we will not be allowed to store a string of any other length in this variable, but if we specify the type of this variable as varchar2(5) then we will be allowed to store strings of variable length. We can store a string of length 3 or 4 or 2 in this variable.
5. What do you mean by data definition language?Â
Data definition language or DDL allows to execution of queries like CREATE, DROP, and ALTER. That is those queries that define the data.
6. What do you mean by data manipulation language?
Data manipulation Language or DML is used to access or manipulate data in the database. It allows us to perform the below-listed functions:Â
- Insert data or rows in a database
- Delete data from the database
- Retrieve or fetch data
- Update data in a database.
7. What is the view in SQL?Â
Views in SQL are a kind of virtual table. A view also has rows and columns as they are on a real table in the database. We can create a view by selecting fields from one or more tables present in the database. A View can either have all the rows of a table or specific rows based on certain conditions.
The CREATE VIEW statement of SQL is used for creating views.Â
Basic Syntax:Â
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;
view_name: Name for the View
table_name: Name of the table
condition: Condition to select rows
8. What do you mean by foreign key?Â
A Foreign key is a field that can uniquely identify each row in another table. And this constraint is used to specify a field as a Foreign key. That is this field points to the primary key of another table. This usually creates a kind of link between the two tables.Â
Consider the two tables as shown below:Â
Orders
| O_ID |
ORDER_NO |
C_ID |
| 1 |
2253 |
3 |
| 2 |
3325 |
3 |
| 3 |
4521 |
2 |
| 4 |
8532 |
1 |
Customers
| C_ID |
NAME |
ADDRESS |
| 1 |
RAMESH |
DELHI |
| 2 |
SURESH |
NOIDA |
| 3 |
DHARMESH |
GURGAON |
As we can see clearly, that the field C_ID in the Orders table is the primary key in the Customers’ table, i.e. it uniquely identifies each row in the Customers table. Therefore, it is a Foreign Key in the Orders table.Â
Syntax:Â
CREATE TABLE Orders
(
O_ID int NOT NULL,
ORDER_NO int NOT NULL,
C_ID int,
PRIMARY KEY (O_ID),
FOREIGN KEY (C_ID) REFERENCES Customers(C_ID)
)
9. What are table and Field?
Table: A table has a combination of rows and columns. Rows are called records and columns are called fields. In MS SQL Server, the tables are being designated within the database and schema names.Â
Field: In DBMS, a database field can be defined as – a single piece of information from a record.
10. What is the primary key?
A Primary Key is one of the candidate keys. One of the candidate keys is selected as the most important and becomes the primary key. There cannot be more than one primary key in a table.
11. What is a Default constraint?
The DEFAULT constraint is used to fill a column with default and fixed values. The value will be added to all new records when no other value is provided.
12. What is normalization?
It is a process of analyzing the given relation schemas based on their functional dependencies and primary keys to achieve the following desirable properties:Â
- Minimizing Redundancy
- Minimizing the Insertion, Deletion, And Update Anomalies
Relation schemas that do not meet the properties are decomposed into smaller relation schemas that could meet desirable properties.Â
13. What is Denormalization?
Denormalization is a database optimization technique in which we add redundant data to one or more tables. This can help us avoid costly joins in a relational database. Note that denormalization does not mean not doing normalization. It is an optimization technique that is applied after normalization.Â
In a traditional normalized database, we store data in separate logical tables and attempt to minimize redundant data. We may strive to have only one copy of each piece of data in the database.
14. What is a query?
An SQL query is used to retrieve the required data from the database. However, there may be multiple SQL queries that yield the same results but with different levels of efficiency. An inefficient query can drain the database resources, reduce the database speed or result in a loss of service for other users. So it is very important to optimize the query to obtain the best database performance.
15. What is a subquery?
In SQL, a Subquery can be simply defined as a query within another query. In other words, we can say that a Subquery is a query that is embedded in the WHERE clause of another SQL query.
16. What are the different operators available in SQL?
There are three operators available in SQL namely:
- Arithmetic Operators
- Logical Operators
- Comparison Operators
17. What is a Constraint?
Constraints are the rules that we can apply to the type of data in a table. That is, we can specify the limit on the type of data that can be stored in a particular column in a table using constraints. For more details please refer to SQL|Constraints article.
18. What is Data Integrity?
Data integrity is defined as the data contained in the database being both correct and consistent. For this purpose, the data stored in the database must satisfy certain types of procedures (rules). The data in a database must be correct and consistent. So, data stored in the database must satisfy certain types of procedures (rules). DBMS provides different ways to implement such types of constraints (rules). This improves data integrity in a database. For more details please refer difference between data security and data integrity article.
19. What is Auto Increment?
Sometimes, while creating a table, we do not have a unique identifier within the table, hence we face difficulty in choosing Primary Key. So as to resolve such an issue, we’ve to manually provide unique keys to every record, but this is often also a tedious task. So we can use the  Auto-Increment feature that automatically generates a numerical Primary key value for every new record inserted. The Auto Increment feature is supported by all the Databases. For more details please refer SQL Auto Increment article.
20. What is MySQL collation?
A MySQL collation is a well-defined set of rules which are used to compare characters of a particular character set by using their corresponding encoding. Each character set in MySQL might have more than one collation, and has, at least, one default collation. Two character sets cannot have the same collation. For more details please refer What are collation and character set in MySQL? article.
21. What are user-defined functions?
We can use User-defined functions in PL/SQL or Java to provide functionality that is not available in SQL or SQL built-in functions. SQL functions and User-defined functions can appear anywhere, that is, wherever an expression occurs.
For example, it can be used in:
- Select a list of SELECT statements.
- Condition of the WHERE clause.
- CONNECT BY, ORDER BY, START WITH, and GROUP BY
- The VALUES clause of the INSERT statement.
- The SET clause of the UPDATE statement.
22. What are all types of user-defined functions?
User-Defined Functions allow people to define their own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type.
Different Kinds of User-Defined Functions created are:
1. Scalar User-Defined Function A Scalar user-defined function returns one of the scalar data types. Text, image, and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value.
2. Inline Table-Value User-Defined Function An Inline Table-Value user-defined function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL select command and, in essence, provide us with a parameterized, non-updateable view of the underlying tables.
3. Multi-statement Table-Value User-Defined Function A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view, as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a TSQL select command or a group of them gives us the capability to, in essence, create a parameterized, non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, it can be used in the FROM clause of a T-SQL command, unlike the behavior found when using a stored procedure which can also return record sets.
23. What is a  stored procedure?
Stored Procedures are created to perform one or more DML operations on databases. It is nothing but a group of SQL statements that accepts some input in the form of parameters and performs some task and may or may not return a value. For more details please refer to our Stored procedures in the SQL article.
24. What are aggregate and scalar functions?
For doing operations on data SQL has many built-in functions, they are categorized into two categories and further sub-categorized into seven different functions under each category. The categories are:
- Aggregate functions: These functions are used to do operations from the values of the column and a single value is returned.
- Scalar functions: These functions are based on user input, these too return a single value.
For more details, please read the SQL | Functions (Aggregate and Scalar Functions) article.
25. What is an ALIAS command?
Aliases are the temporary names given to a table or column for the purpose of a particular SQL query. It is used when the name of a column or table is used other than its original name, but the modified name is only temporary.
- Aliases are created to make table or column names more readable.
- The renaming is just a temporary change and the table name does not change in the original database.
- Aliases are useful when table or column names are big or not very readable.
- These are preferred when there is more than one table involved in a query.
For more details, please read the SQL | Aliases article.
26. What are Union, minus, and Interact commands?
Set Operations in SQL eliminate duplicate tuples and can be applied only to the relations which are union compatible. Set Operations available in SQL are :
- Set Union
- Set Intersection
- Set Difference
UNION Operation: This operation includes all the tuples which are present in either of the relations. For example: To find all the customers who have a loan or an account or both in a bank.
SELECT CustomerName FROM Depositor
UNION
SELECT CustomerName FROM Borrower ;
The union operation automatically eliminates duplicates. If all the duplicates are supposed to be retained, UNION ALL is used in place of UNION.Â
INTERSECT Operation:Â This operation includes the tuples which are present in both of the relations. For example: To find the customers who have a loan as well as an account in the bank:
SELECT CustomerName FROM Depositor
INTERSECT
SELECT CustomerName FROM Borrower ;
The Intersect operation automatically eliminates duplicates. If all the duplicates are supposed to be retained, INTERSECT ALL is used in place of INTERSECT.Â
EXCEPT for Operation: This operation includes tuples that are present in one relationship but should not be present in another relationship. For example: To find customers who have an account but no loan at the bank:
SELECT CustomerName FROM Depositor
EXCEPT
SELECT CustomerName FROM Borrower ;
The Except operation automatically eliminates the duplicates. If all the duplicates are supposed to be retained, EXCEPT ALL is used in place of EXCEPT.
27. What is a T-SQL?
T-SQL is an abbreviation for Transact Structure Query Language. It is a product by Microsoft and is an extension of SQL Language which is used to interact with relational databases. It is considered to perform best with Microsoft SQL servers. T-SQL statements are used to perform the transactions to the databases. T-SQL has huge importance since all the communications with an instance of an SQL server are done by sending Transact-SQL statements to the server. Users can also define functions using T-SQL.
Types of T-SQL functions are :
- Aggregate functions.
- Ranking functions. There are different types of ranking functions.
- Rowset function.
- Scalar functions.
28. What is ETL in SQL?
ETL is a process in Data Warehousing and it stands for Extract, Transform, and Load. It is a process in which an ETL tool extracts the data from various data source systems, transforms it in the staging area, and then finally, loads it into the Data Warehouse system. These are three database functions that are incorporated into one tool to pull data out from one database and put data into another database.
29. How to copy tables in SQL?
Sometimes, in SQL, we need to create an exact copy of an already defined (or created) table. MySQL enables you to perform this operation. Because we may need such duplicate tables for testing the data without having any impact on the original table and the data stored in it.Â
CREATE TABLE Contact List(Clone_1) LIKE Original_table;
For more details, Please read Cloning Table in the MySQL article.
30.  What is SQL injection?
SQL injection is a technique used to exploit user data through web page inputs by injecting SQL commands as statements. Basically, these statements can be used to manipulate the application’s web server by malicious users.
- SQL injection is a code injection technique that might destroy your database.
- SQL injection is one of the most common web hacking techniques.
- SQL injection is the placement of malicious code in SQL statements, via web page input.
For more details, please read the SQL | Injection article.
31. Can we disable a trigger? If yes, how?
 Yes, we can disable a trigger in PL/SQL. If consider temporarily disabling a trigger and one of the following conditions is true:
- An object that the trigger references is not available.
- We must perform a large data load and want it to proceed quickly without firing triggers.
- We are loading data into the table to which the trigger applies.
- We disable a trigger using the ALTER TRIGGER statement with the DISABLE option.
- We can disable all triggers associated with a table at the same time using the ALTER TABLE statement with the DISABLE ALL TRIGGERS option.
32. What are the differences between SQL and PL/SQL?Â
Some common differences between SQL and PL/SQL are as shown below:Â
|
SQL
|
PL/SQL
|
|
SQL is a query execution or commanding language
|
PL/SQL is a complete programming language
|
|
SQL is a data-oriented language.
|
PL/SQL is a procedural language
|
|
SQL is very declarative in nature.
|
PL/SQL has a procedural nature.
|
|
It is used for manipulating data.
|
It is used for creating applications.
|
|
We can execute one statement at a time in SQL
|
We can execute blocks of statements in PL/SQL
|
|
SQL tells databases, what to do?
|
PL/SQL tells databases how to do.
|
|
We can embed SQL in PL/SQL
|
We can not embed PL/SQL in SQL
|
33. What is the difference between BETWEEN and IN operators in SQL?Â
BETWEEN: The BETWEEN operator is used to fetch rows based on a range of values.Â
For example,Â
SELECT * FROM Students
WHERE ROLL_NO BETWEEN 20 AND 30;
This query will select all those rows from the table. Students where the value of the field ROLL_NO lies between 20 and 30.Â
IN: The IN operator is used to check for values contained in specific sets.Â
For example,Â
SELECT * FROM Students
WHERE ROLL_NO IN (20,21,23);
This query will select all those rows from the table Students where the value of the field ROLL_NO is either 20 or 21 or 23.
34. Write an SQL query to find the names of employees starting with ‘A’.Â
The LIKE operator of SQL is used for this purpose. It is used to fetch filtered data by searching for a particular pattern in the where clause.Â
The Syntax for using LIKE is,Â
SELECT column1,column2 FROM table_name WHERE column_name LIKE pattern;
LIKE: operator name
pattern: exact value extracted from the pattern to get related data in result set.
The required query is:Â
SELECT * FROM Employees WHERE EmpName like 'A%' ;
You may refer to this article WHERE clause for more details on the LIKE operator.
35. What is the difference between primary key and unique constraints?Â
The primary key cannot have NULL values, the unique constraints can have NULL values. There is only one primary key in a table, but there can be multiple unique constraints. The primary key creates the clustered index automatically but the unique key does not.
36. What is a join in SQL? What are the types of joins?Â
An SQL Join statement is used to combine data or rows from two or more tables based on a common field between them. Different types of Joins are:Â
- INNER JOIN: The INNER JOIN keyword selects all rows from both tables as long as the condition is satisfied. This keyword will create the result set by combining all rows from both the tables where the condition satisfies i.e. the value of the common field will be the same.
- LEFT JOIN: This join returns all the rows of the table on the left side of the join and matching rows for the table on the right side of the join. For the rows for which there is no matching row on the right side, the result set will be null. LEFT JOIN is also known as LEFT OUTER JOIN
- RIGHT JOIN: RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join and matching rows for the table on the left side of the join. For the rows for which there is no matching row on the left side, the result set will contain null. RIGHT JOIN is also known as RIGHT OUTER JOIN.
- FULL JOIN: FULL JOIN creates the result set by combining the results of both LEFT JOIN and RIGHT JOIN. The result set will contain all the rows from both tables. For the rows for which there is no matching, the result set will contain NULL values.
37. What is an index?Â
A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and the use of more storage space to maintain the extra copy of data. Data can be stored only in one order on a disk. To support faster access according to different values, a faster search like a binary search for different values is desired. For this purpose, indexes are created on tables. These indexes need extra space on the disk, but they allow faster search according to different frequently searched values.
38. What is the On Delete cascade constraint?
An ‘ON DELETE CASCADE’ constraint is used in MySQL to delete the rows from the child table automatically when the rows from the parent table are deleted. For more details, please read MySQL – On Delete Cascade constraint article.
39. Explain  WITH clause in SQL?
The WITH clause provides a way relationship of defining a temporary relationship whose definition is available only to the query in which the with clause occurs. SQL applies predicates in the WITH clause after groups have been formed, so aggregate functions may be used.
40. What are all the different attributes of indexes?
The indexing has various attributes:
- Access Types: This refers to the type of access such as value-based search, range access, etc.
- Access Time: It refers to the time needed to find a particular data element or set of elements.
- Insertion Time: It refers to the time taken to find the appropriate space and insert new data.
- Deletion Time: Time is taken to find an item and delete it as well as update the index structure.
- Space Overhead: It refers to the additional space required by the index.
41. What is a Cursor?
The cursor is a Temporary Memory or Temporary Work Station. It is Allocated by Database Server at the Time of Performing DML operations on the Table by the User. Cursors are used to store Database Tables.Â
42. Write down various types of relationships in SQL?
There are various relationships, namely:
- One-to-One Relationship.
- One to Many Relationships.
- Many to One Relationship.
- Self-Referencing Relationship.
43. What is a trigger?
The trigger is a statement that a system executes automatically when there is any modification to the database. In a trigger, we first specify when the trigger is to be executed and then the action to be performed when the trigger executes. Triggers are used to specify certain integrity constraints and referential constraints that cannot be specified using the constraint mechanism of SQL.
44. What is the difference between SQL DELETE and SQL TRUNCATE commands?
|
SQL DELETE
|
SQL TRUNCATE
|
| The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. |
TRUNCATE TABLE removes the data by deallocating the data pages used to store the table data and records only the page deallocations in the transaction log. |
| DELETE command is slower than the identityTRUNCATE command. |
While the TRUNCATE command is faster than the DELETE command. |
| To use Delete you need DELETE permission on the table. |
To use Truncate on a table we need at least ALTER permission on the table. |
| The identity of the column retains the identity after using DELETE Statement on the table. |
The identity of the column is reset to its seed value if the table contains an identity column. |
| The delete can be used with indexed views. |
Truncate cannot be used with indexed views. |
45. What is the difference between Cluster and Non-Cluster Index?
| CLUSTERED INDEX |
NON-CLUSTERED INDEX |
| The clustered index is faster. |
The non-clustered index is slower. |
| The clustered index requires less memory for operations. |
The non-Clustered index requires more memory for operations. |
| In a clustered index, the index is the main data. |
In the Non-Clustered index, the index is a copy of data. |
| A table can have only one clustered index. |
A table can have multiple non-clustered indexes. |
| The clustered index has an inherent ability to store data on the disk. |
The non-Clustered index does not have the inherent ability to store data on the disk. |
| Clustered indexes store pointers to block not data. |
The non-Clustered index store both value and a pointer to the the the actual row that holds data. |
| In Clustered index leaf nodes are actual data itself. |
In a Non-Clustered index, leaf nodes are not the actual data itself rather they only contain included columns. |
| In the Clustered index, the Clustered key defines the order of data within the table. |
In the Non-Clustered index, the index key defines the order of data within the index. |
| A Clustered index is a type of index in which table records are physically reordered to match the index. |
A Non-Clustered index is a special type of index in which the logical order of index does not match the physical stored order of the rows on the disk. |
For more details please refer Difference between Clustered index and the No-Clustered index article.
46.  What is a Live Lock?
Livelock occurs when two or more processes continually repeat the same interaction in response to changes in the other processes without doing any useful work. These processes are not in the waiting state, and they are running concurrently. This is different from a deadlock because in a deadlock all processes are in the waiting state.
47. What is Case WHEN in SQL?
Control statements form an important part of most languages since they control the execution of other sets of statements. These are found in SQL too and should be exploited for uses such as query filtering and query optimization through careful selection of tuples that match our requirements. In this post, we explore the Case-Switch statement in SQL. The CASE statement is SQL’s way of handling if/then logic.
Syntax 1:
CASE case_value WHEN when_value THEN statement_list [WHEN when_value THEN statement_list] … [ELSE statement_list]END CASE
Syntax 2:
CASE WHEN search_condition THEN statement_list [WHEN search_condition THEN statement_list] … [ELSE statement_list]END CASE
For more details, please read the SQL | Case Statement article.
Advanced SQL Interview Questions and Answers
48. Name different types of case manipulation functions available in SQL.Â
There are three types of case manipulation functions available in SQL. They are,Â
- LOWER: The purpose of this function is to return the string in lowercase. It takes a string as an argument and returns the string by converting it into lower case.Â
Syntax:Â
LOWER(‘string’)
- UPPER: The purpose of this function is to return the string in uppercase. It takes a string as an argument and returns the string by converting it into uppercase.Â
Syntax:
UPPER(‘string’)
- INITCAP: The purpose of this function is to return the string with the first letter in uppercase and the rest of the letters in lowercase.Â
Syntax:Â
INITCAP(‘string’)
49. What are local and global variables and their differences?
Global Variable: In contrast, global variables are variables that are defined outside of functions. These variables have global scope, so they can be used by any function without passing them to the function as parameters.
Local Variable: Local variables are variables that are defined within functions. They have local scope, which means that they can only be used within the functions that define them.
50. Name the function which is used to remove spaces at the end of a string?
In SQL, the spaces at the end of the string are removed by a trim function.
Syntax:
Trim(s) , Where s is a any string.
51. What is the difference between TRUNCATE and DROP statements?
| SQL DROP |
TRUNCATE |
| The DROP command is used to remove the table definition and its contents. |
Whereas the TRUNCATE command is used to delete all the rows from the table. |
| In the DROP command, table space is freed from memory. |
While the TRUNCATE command does not free the table space from memory. |
| DROP is a DDL(Data Definition Language) command. |
Whereas the TRUNCATE is also a DDL(Data Definition Language) command. |
| In the DROP command, a view of the table does not exist. |
While in this command, a view of the table exists. |
| In the DROP command, integrity constraints will be removed. |
While in this command, integrity constraints will not be removed. |
| In the DROP command, undo space is not used. |
While in this command, undo space is used but less than DELETE. |
| The DROP command is quick to perform but gives rise to complications. |
While this command is faster than DROP. |
For more details, please read the Difference between DROP and TRUNCATE in the SQLÂ article.
52. Which operator is used in queries for pattern matching?
LIKE operator: It is used to fetch filtered data by searching for a particular pattern in the where clause.
Syntax:
SELECT column1,column2 FROM table_name WHERE column_name LIKE pattern;
LIKE: operator name
53. Define SQL Order by the statement?
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns.
- By default ORDER BY sorts the data in ascending order.
- We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
For more details please read SQL | ORDER BY article.
54. Explain SQL Having statement?
HAVING is used to specify a condition for a group or an aggregate function used in the select statement. The WHERE clause selects before grouping. The HAVING clause selects rows after grouping. Unlike the HAVING clause, the WHERE clause cannot contain aggregate functions. See Having vs Where Clause?Â
55. Explain SQL AND OR statement with an example?
In SQL, the AND & OR operators are used for filtering the data and getting precise results based on conditions. The AND and OR operators are used with the WHERE clause.
These two operators are called conjunctive operators.
- AND Operator: This operator displays only those records where both conditions condition 1 and condition 2 evaluate to True.
- OR Operator:Â This operator displays the records where either one of the conditions condition 1 and condition 2 evaluates to True. That is, either condition1 is True or condition2 is True.
For more details please read the SQL | AND and OR operators article.
56. Define BETWEEN statements in SQL?
The SQL BETWEEN condition allows you to easily test if an expression is within a range of values (inclusive). The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement. The SQL BETWEEN Condition will return the records where the expression is within the range of value1 and value2.
For more details please read SQL | Between & I operator article.
57. Why do we use  Commit and Rollback commands?
| COMMIT |
ROLLBACK |
| COMMIT permanently saves the changes made by the current transaction. |
ROLLBACK undo the changes made by the current transaction. |
| The transaction can not undo changes after COMMIT execution. |
Transaction reaches its previous state after ROLLBACK. |
| When the transaction is successful, COMMIT is applied. |
When the transaction is aborted, ROLLBACK occurs. |
For more details please read the Difference between Commit and Rollback in SQL article.
58. What are ACID properties?
A transaction is a single logical unit of work that accesses and possibly modifies the contents of a database. Transactions access data using read-and-write operations. In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties. ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that guarantee that database transactions are processed reliably. For more details please read ACID properties in the DBMS article.
59. Are NULL values the same as zero or a blank space?Â
In SQL, zero or blank space can be compared with another zero or blank space. whereas one null may not be equal to another null. null means data might not be provided or there is no data.
60. What is the need for group functions in SQL?Â
In database management, group functions, also known as aggregate functions, Â is a function where the values of multiple rows are grouped together as input on certain criteria to form a single value of more significant meaning.
Various Group Functions
1) Count()
2) Sum()
3) Avg()
4) Min()
5) Max()
For more details please read the Aggregate functions in the SQL article.
61. What is the need for a MERGE statement?
The MERGE command in SQL is actually a combination of three SQL statements: INSERT, UPDATE, and DELETE. In simple words, the MERGE statement in SQL provides a convenient way to perform all these three operations together which can be very helpful when it comes to handling large running databases. But unlike INSERT, UPDATE, and DELETE statements MERGE statement requires a source table to perform these operations on the required table which is called a target table. For more details please read the SQL | MERGE Statement article.
62. How can you fetch common records from two tables?
The below statement could be used to get data from multiple tables, so, we need to use join to get data from multiple tables.
Syntax :
SELECT tablenmae1.colunmname, tablename2.columnnmae
FROM tablenmae1
JOIN tablename2
ON tablenmae1.colunmnam = tablename2.columnnmae
ORDER BY columnname;
For more details and examples, please read SQL | SELECT data from the Multiple Tables article.
63. What are the advantages of PL/SQL functions?
The advantages of PL / SQL functions are as follows:Â
- We can make a single call to the database to run a block of statements. Thus, it improves the performance against running SQL multiple times. This will reduce the number of calls between the database and the application.
- We can divide the overall work into small modules which becomes quite manageable, also enhancing the readability of the code.
- It promotes reusability.
- It is secure since the code stays inside the database, thus hiding internal database details from the application(user). The user only makes a call to the PL/SQL functions. Hence, security and data hiding is ensured.
64. What is the SQL query to display the current date?
CURRENT_DATEÂ returns to the current date. This function returns the same value if it is executed more than once in a single statement, which means that the value is fixed, even if there is a long delay between fetching rows in a cursor.
Syntax:
CURRENT_DATE
or
CURRENT DATE
65. What are Nested Triggers?
A trigger can also contain INSERT, UPDATE, and DELETE logic within itself, so when the trigger is fired because of data modification it can also cause another data modification, thereby firing another trigger. A trigger that contains data modification logic within itself is called a nested trigger.
66. How to find the available constraint information in the table?
In SQL Server the data dictionary is a set of database tables used to store information about a database’s definition. One can use these data dictionaries to check the constraints on an already existing table and to change them(if possible). For more details please read SQL | Checking Existing Constraint on a table article.
67.  How do we avoid getting duplicate entries in a query without using the distinct keyword?
DISTINCT is useful in certain circumstances, but it has drawbacks that it can increase the load on the query engine to perform the sort (since it needs to compare the result set to itself to remove duplicates). We can remove duplicate entries using the following options:
- Remove duplicates using row numbers.
- Remove duplicates using self-Join.
- Remove duplicates using group by.
For more details, please read SQL | Remove duplicates without distinct articles.
68. The difference between NVL and NVL2 functions?
These functions work with any data type and pertain to the use of null values in the expression list. These are all single-row functions i.e. provide one result per row.
NVL(expr1, expr2): In SQL, NVL() converts a null value to an actual value. Data types that can be used are date, character, and number. Data types must match with each other. i.e. expr1 and expr2 must be of the same data type.
Syntax:
NVL (expr1, expr2)
NVL2(expr1, expr2, expr3):Â The NVL2 function examines the first expression. If the first expression is not null, then the NVL2 function returns the second expression. If the first expression is null, then the third expression is returned i.e. If expr1 is not null, NVL2 returns expr2. If expr1 is null, NVL2 returns expr3. The argument expr1 can have any data type.
Syntax:
NVL2 (expr1, expr2, expr3)
For more details please read SQL general functions | NVL, NVL2, DECODE, COALESCE, NULLIF, LNNVL, and NANVL article.
69.  What is the difference between COALESCE() & ISNULL()?Â
COALESCE():Â COALESCE function in SQL returns the first non-NULL expression among its arguments. If all the expressions evaluate to null, then the COALESCE function will return null.
Syntax:
SELECT column(s), CAOLESCE(expression_1,….,expression_n)FROM table_name;
ISNULL():Â The ISNULL function has different uses in SQL Server and MySQL. In SQL Server, ISNULL() function is used to replace NULL values.
Syntax:
SELECT column(s), ISNULL(column_name, value_to_replace)FROM table_name;
For more details, please read the SQL | Null functions article.
70. Name the operator which is used in the query for appending two strings?
In SQL for appending two strings, the ” Concentration operator” Â is used and its symbol is ” || “.
Conclusion
In conclusion, mastering SQL interview questions is crucial for data analysts, data engineers, and business analysts aiming to excel in their respective fields. This article has provided a comprehensive set of SQL interview questions and answers designed to prepare you thoroughly.
By understanding and practicing these questions, you enhance your ability to tackle the challenges posed in SQL-related interviews effectively, ultimately paving the way for a successful career in data handling and analysis. Remember, each question is an opportunity to demonstrate your analytical prowess and technical expertise, essential traits for any aspiring professional in these critical roles.
Similar Reads
SQL Tutorial
In this SQL tutorial, you’ll learn all the basic to advanced SQL concepts like SQL queries, SQL join, SQL injection, SQL insert, and creating tables in SQL. SQL is easy to learn, there are no prerequisites to learn SQL. So, SQL is a standard database language used to access and manipulate data in da
11 min read
SQL Basics
What is Database?
A database is an organized collection of data stored in a computer system and usually managed by a database management system (DBMS). The most commonly used types of databases are Relational and NoSQL.The data in relational databases is modeled in tables, making querying and processing efficient. St
7 min read
Types of Databases
Every company relies on data, making its management essential. Data can be both Structured and Unstructured. Efficient data handling ensures that data is securely stored, accessed, and modified as needed, supporting smooth business operations. Proper data management not only aids in decision-making
9 min read
Introduction of DBMS (Database Management System)
A database is a collection of interrelated data that helps in the efficient retrieval, insertion, and deletion of data from the database and organizes the data in the form of tables, views, schemas, reports, etc. For Example, a university database organizes the data about students, faculty, admin st
8 min read
Non-Relational Databases and Their Types
In the area of database management, the data is arranged in two ways which are Relational Databases (SQL) and Non-Relational Databases (NoSQL). While relational databases organize data into structured tables, non-relational databases use various flexible data models like key-value pairs, documents,
7 min read
What is SQL?
SQL stands for Structured Query Language. It is a standardized programming language used to manage and manipulate relational databases. It enables users to perform a variety of tasks such as querying data, creating and modifying database structures, and managing access permissions. SQL is widely use
10 min read
SQL Data Types
SQL Data Types are the pillar of relational database schema design. It ensures that data is stored efficiently and accurately. Data types define the type of value a column can hold, such as numbers, text, or dates. Understanding SQL Data Types is critical for database administrators, developers, and
5 min read
SQL Operators
SQL operators are important in database management systems (DBMS) as they allow us to manipulate and retrieve data efficiently. Operators in SQL perform arithmetic, logical, comparison, bitwise, and other operations to work with database values. Understanding SQL operators is crucial for performing
5 min read
SQL Commands | DDL, DQL, DML, DCL and TCL Commands
SQL commands are essential for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will
7 min read
Create Database in SQL
SQL CREATE DATABASE
The CREATE DATABASE statement is a foundational SQL command used to create new databases in SQL-based Database Management Systems (DBMS), including MySQL, PostgreSQL, SQL Server, and others. Understanding how to use this command effectively is crucial for developers, database administrators, and any
4 min read
SQL DROP DATABASE
The SQL DROP DATABASE statement is an important command used to permanently delete a database from the Database Management System (DBMS). When executed, this command removes the database and all its associated objects, including tables, views, stored procedures, and other entities. In this article,
4 min read
SQL Query to Rename Database
Renaming a database in SQL is an essential task that database administrators and developers frequently perform. Whether you’re reorganizing your data, correcting naming conventions, or simply updating your project structure, knowing how to rename a database properly is critical. In this article, we'
3 min read
SQL Select Database
The USE DATABASE statement is a command in certain SQL-based database management systems that allows users to select and set a specific database as the default for the current session. By selecting a database, subsequent queries are executed within the context of that database, making it easier to i
3 min read
Tables in SQL
SQL CREATE TABLE
The SQL CREATE TABLE statement is a foundational command used to define and structure a new table in a database. By specifying the columns, data types, and constraints such as PRIMARY KEY, NOT NULL, and CHECK, helps you design the database schema. In this article, we'll learn the syntax, best practi
4 min read
SQL DROP TABLE
The DROP TABLE command in SQL is a powerful and essential tool used to permanently delete a table from a database, along with all of its data, structure, and associated constraints such as indexes, triggers, and permissions. When executed, this command removes the table and all its contents, making
4 min read
SQL DELETE Statement
The SQL DELETE statement is one of the most commonly used commands in SQL (Structured Query Language). It allows you to remove one or more rows from the table depending on the situation. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the tabl
4 min read
ALTER (RENAME) in SQL
In SQL, making structural changes to a database is often necessary. Whether it's renaming a table or a column, adding new columns, or modifying data types, the SQL ALTER TABLE command plays a critical role. This command provides flexibility to manage and adjust database schemas without affecting the
4 min read
DROP and TRUNCATE in SQL
The DROP and TRUNCATE commands in SQL are used to remove data from a table, but they work differently. Understanding the difference between these two commands is important for proper database management, especially when dealing with large amounts of data. This article provides an in-depth explanatio
4 min read
SQL Query to Create a Backup Table
Relational databases play an important role in managing data, especially during complex operations like updates and deletions. To maintain data integrity, it is essential to back up tables before making changes. SQL backup tables ensure the safety of the original dataset, allow for data recovery, an
5 min read
What is Temporary Table in SQL?
A temporary table in SQL is an important tool for maintaining intermediate results during query execution. They help store temporary data without affecting the underlying permanent tables. In this article, we’ll explore temporary tables in SQL, their types (local vs. global), and how to use them eff
3 min read
SQL ALTER TABLE
The SQL ALTER TABLE statement is a powerful tool that allows you to modify the structure of an existing table in a database. Whether you're adding new columns, modifying existing ones, deleting columns, or renaming them, the ALTER TABLE statement enables you to make changes without losing the data s
4 min read
SQL Queries
SQL SELECT Query
The select query in SQL is one of the most commonly used SQL commands to retrieve data from a database. With the select command in SQL, users can access data and retrieve specific records based on various conditions, making it an essential tool for managing and analyzing data. In this article, we’ll
4 min read
SQL TOP, LIMIT, FETCH FIRST Clause
SQL TOP, LIMIT, and FETCH FIRST clauses are used to retrieve a specific number of records from a table. These clauses are especially useful in large datasets with thousands of records. Each of these SQL clauses performs a similar operation of limiting the results returned by a query, but different d
8 min read
SQL SELECT FIRST
The SELECT FIRST clause is used in some SQL databases (primarily MS Access) to retrieve the first record from a table based on the order in which data is stored or queried. It is commonly used when you need to access just one entry, such as the first row based on the natural order or after sorting b
3 min read
SQL - SELECT LAST
SELECT LAST is a concept or function often used to describe retrieving the last record or last row from a table in SQL. Although MS Access supports a LAST() function to directly fetch the last value from a column, this function is not universally supported across all SQL-based databases. Instead, in
5 min read
SQL - SELECT RANDOM
In SQL, the RANDOM() function is used to fetch random rows from a table. It is an extremely useful function in various applications, such as selecting random users, retrieving random questions from a pool, or even for random sampling in data analysis. In this article, we will explore how to use RAND
4 min read
SQL SELECT IN Statement
The IN operator in SQL is used to compare a column's value against a set of values. It returns TRUE if the column's value matches any of the values in the specified list, and FALSE if there is no match. In this article, we will learn how IN operator works and provide practical examples to help you b
4 min read
SQL - SELECT DATE
SQL (Structured Query Language) can work with datetime data types. SELECT DATE is an important concept when retrieving records that filter data based on date. Whether you work with employee records, transaction records, or product sales, modifying and retrieving date data is often important for your
3 min read
SQL Query to Insert Multiple Rows
In SQL, the INSERT statement is used to add new records to a database table. When you need to insert multiple rows in a single query, the INSERT statement becomes efficient. In this article, We will learn different methods such as using basic INSERT statements, utilizing INSERT INTO ... SELECT for b
4 min read
SQL INSERT INTO Statement
The INSERT INTO statement is a fundamental SQL command used to add new rows of data into a table in a database. It is one of the most commonly used SQL statements for manipulating data and plays a key role in database management. This article will explore the SQL INSERT INTO statement in detail, sho
8 min read
SQL UPDATE Statement
In SQL, the UPDATE statement is used to modify existing records in a table. Whether you need to update a single record or multiple rows at once, SQL provides the necessary functionality to make these changes. The UPDATE statement is essential for maintaining the integrity of your data by allowing yo
4 min read
SQL DELETE Statement
The SQL DELETE statement is one of the most commonly used commands in SQL (Structured Query Language). It allows you to remove one or more rows from the table depending on the situation. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the tabl
4 min read
SQL Query to Delete Duplicate Rows
Duplicate rows in a database can cause inaccurate results, waste storage space, and slow down queries. Cleaning duplicate records from our database is an essential maintenance task for ensuring data accuracy and performance. Duplicate rows in a SQL table can lead to data inconsistencies and performa
5 min read
SQL Clauses
SQL | WHERE Clause
The SQL WHERE clause allows to filtering of records in queries. Whether you're retrieving data, updating records, or deleting entries from a database, the WHERE clause plays an important role in defining which rows will be affected by the query. Without it, SQL queries would return all rows in a tab
4 min read
SQL | WITH Clause
The SQL WITH clause, also known as Common Table Expressions (CTEs), is a powerful tool that simplifies complex SQL queries, improves readability, and enhances performance by defining temporary result sets that can be reused multiple times. Whether we're working on aggregating data, analyzing large d
5 min read
SQL HAVING Clause with Examples
The HAVING clause was introduced in SQL to allow the filtering of query results based on aggregate functions and groupings. Unlike the WHERE clause, which filters individual rows before any grouping occurs, the HAVING clause works on groups of data that have been aggregated using functions like SUM(
4 min read
SQL ORDER BY
The ORDER BY clause in SQL is a powerful feature used to sort query results in either ascending or descending order based on one or more columns. Whether you're presenting data to users or analyzing large datasets, sorting the results in a structured way is essential. In this article, we’ll explain
5 min read
SQL | GROUP BY
The GROUP BY statement in SQL is used for organizing and summarizing data based on identical values in specified columns. By leveraging the GROUP BY clause, users can apply aggregate functions like SUM, COUNT, AVG, MIN, and MAX to each group, making it easier to perform detailed data analysis. In th
5 min read
SQL LIMIT Clause
The LIMIT clause in SQL is used to restrict the number of rows returned in a query result. This clause is particularly useful when working with large datasets, as it allows you to limit the output to only the rows you need for analysis or display. Whether you're looking to paginate results, find top
4 min read
SQL Operators
SQL AND and OR Operators
The SQL AND and OR operators are used to filter data based on multiple conditions. These logical operators allow users to retrieve precise results from a database by combining various conditions in SELECT, INSERT, UPDATE, and DELETE statements. In this article, we'll learn the AND and OR operators,
3 min read
SQL AND and OR Operators
The SQL AND and OR operators are used to filter data based on multiple conditions. These logical operators allow users to retrieve precise results from a database by combining various conditions in SELECT, INSERT, UPDATE, and DELETE statements. In this article, we'll learn the AND and OR operators,
3 min read
SQL LIKE Operator
The SQL LIKE operator is used for performing pattern-based searches in a database. It is used in combination with the WHERE clause to filter records based on specified patterns, making it essential for any database-driven application that requires flexible search functionality. In this article, we w
5 min read
SQL IN Operator
The SQL IN operator filters data based on a list of specific values. In general, we can only use one condition in the Where clause, but the IN operator allows us to specify multiple values. In this article, we will learn about the IN operator in SQL by understanding its syntax and examples. IN Opera
4 min read
SQL NOT Operator
The SQL NOT Operator is a logical operator used to negate or reverse the result of a condition in SQL queries. It is commonly used with the WHERE clause to filter records that do not meet a specified condition, helping you exclude certain values from your results. In this article, we will learn ever
3 min read
SQL NOT EQUAL Operator
The SQL NOT EQUAL operator is a comparison operator used to check if two expressions are not equal to each other. It helps filter out records that match certain conditions, making it a valuable tool in SQL queries. In this article, We will explore the SQL NOT EQUAL operator, including its syntax, us
4 min read
SQL IS NULL
The SQL IS NULL operator is a logical operator used to identify and filter out rows with NULL values in a column. A NULL value represents missing or undefined data in a database. It is different from a zero value or blank space, and it indicates that the value is unknown. In this article, we will le
4 min read
SQL UNION Operator
The SQL UNION operator is used to combine the result sets of two or more SELECT queries into a single result set. It is a powerful tool in SQL that helps aggregate data from multiple tables, especially when the tables have similar structures. In this guide, we'll explore the SQL UNION operator, how
4 min read
SQL UNION ALL
UNION ALL Operator is used to combine the results of two or more SELECT statements into a single result set. Unlike the UNION operator, which eliminates duplicate records and UNION ALL includes all duplicates. This makes UNION ALL it faster and more efficient when we don't need to remove duplicates.
4 min read
SQL | Except Clause
The SQL EXCEPT operator is used to return the rows from the first SELECT statement that are not present in the second SELECT statement. This operator is conceptually similar to the subtract operator in relational algebra. It is particularly useful for excluding specific data from your result set. In
4 min read
SQL BETWEEN Operator
The BETWEEN operator in SQL is used to filter records within a specific range. Whether applied to numeric, text, or date columns it simplifies the process of retrieving data that falls within a particular boundary. In this article, we will explore the SQL BETWEEN operator with examples. SQL BETWEEN
3 min read
SQL | ALL and ANY
In SQL, the ALL and ANY operators are logical operators used to compare a value with a set of values returned by a subquery. These operators provide powerful ways to filter results based on a range of conditions. In this article, we will explore ALL and ANY in SQL, their differences, and how to use
4 min read
SQL | ALL and ANY
In SQL, the ALL and ANY operators are logical operators used to compare a value with a set of values returned by a subquery. These operators provide powerful ways to filter results based on a range of conditions. In this article, we will explore ALL and ANY in SQL, their differences, and how to use
4 min read
SQL | INTERSECT Clause
In SQL, the INTERSECT clause is used to retrieve the common records between two SELECT queries. It returns only the rows that are present in both result sets. This makes INTERSECT an essential clause when you need to find overlapping data between two or more queries. The INTERSECT operator is part o
4 min read
SQL | EXISTS
The SQL EXISTS condition is used to test whether a correlated subquery returns any results. If the subquery returns at least one row, the EXISTS condition evaluates to TRUE; otherwise, it evaluates to FALSE. The EXISTS operator can be used in various SQL statements like SELECT, UPDATE, INSERT, and D
3 min read
SQL CASE Statement
The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing
4 min read
SQL Aggregate Functions
SQL Aggregate functions
SQL Aggregate Functions are used to perform calculations on a set of rows and return a single value. They are often used with the GROUP BY clause in SQL to summarize data for each group. Commonly used aggregate functions include COUNT(), SUM(), AVG(), MIN(), and MAX(). In this article, we'll learn t
3 min read
SQL COUNT(), AVG() and SUM() Function
SQL aggregate functions, such as COUNT(), AVG(), and SUM(), are essential tools for performing mathematical analysis on data. These functions allow you to gather valuable insights from your database, such as calculating totals, and averages, and counting specific rows. In this article, we’ll explain
3 min read
SQL COUNT(), AVG() and SUM() Function
SQL aggregate functions, such as COUNT(), AVG(), and SUM(), are essential tools for performing mathematical analysis on data. These functions allow you to gather valuable insights from your database, such as calculating totals, and averages, and counting specific rows. In this article, we’ll explain
3 min read
SQL MIN() and MAX() Functions
The SQL MIN() and MAX() functions are essential aggregate functions in SQL used for data analysis. They allow you to extract the minimum and maximum values from a specified column, respectively, making them invaluable when working with numerical, string, or date-based data. In this article, we will
4 min read
SQL MIN() and MAX() Functions
The SQL MIN() and MAX() functions are essential aggregate functions in SQL used for data analysis. They allow you to extract the minimum and maximum values from a specified column, respectively, making them invaluable when working with numerical, string, or date-based data. In this article, we will
4 min read
SQL COUNT(), AVG() and SUM() Function
SQL aggregate functions, such as COUNT(), AVG(), and SUM(), are essential tools for performing mathematical analysis on data. These functions allow you to gather valuable insights from your database, such as calculating totals, and averages, and counting specific rows. In this article, we’ll explain
3 min read
SQL Data Constraints
SQL NOT NULL Constraint
In SQL, constraints are used to enforce rules on data, ensuring the accuracy, consistency, and integrity of the data stored in a database. One of the most commonly used constraints is the NOT NULL constraint, which ensures that a column cannot have NULL values. This is important for maintaining data
3 min read
SQL | UNIQUE Constraint
In SQL, constraints play a vital role in maintaining the integrity and accuracy of the data stored in a database. One such constraint is the UNIQUE constraint, which ensures that all values in a column (or a combination of columns) are distinct, preventing duplicate entries. This constraint is espec
4 min read
SQL PRIMARY KEY Constraint
The PRIMARY KEY constraint in SQL is one of the most important constraints used to ensure data integrity in a database table. A primary key uniquely identifies each record in a table, preventing duplicate or NULL values in the specified column(s). Understanding how to properly implement and use the
5 min read
SQL FOREIGN KEY Constraint
The FOREIGN KEY constraint is a fundamental concept in relational databases, ensuring data integrity by enforcing relationships between tables. By linking a child table to a parent table, the foreign key establishes referential integrity. This constraint ensures that the values in the foreign key co
4 min read
Composite Key in SQL
A composite key is a primary key that is made up of more than one column to uniquely identify records in a table. Unlike a single-column primary key, a composite key combines two or more columns to ensure uniqueness. While any of the individual columns in a composite key might not be unique on their
2 min read
SQL | UNIQUE Constraint
In SQL, constraints play a vital role in maintaining the integrity and accuracy of the data stored in a database. One such constraint is the UNIQUE constraint, which ensures that all values in a column (or a combination of columns) are distinct, preventing duplicate entries. This constraint is espec
4 min read
SQL - ALTERNATE KEY
Alternate Key is any candidate key not selected as the primary key. So, while a table may have multiple candidate keys (sets of columns that could uniquely identify rows), only one of them is designated as the Primary Key. The rest of these candidate keys become Alternate Keys. In other words, we ca
4 min read
SQL | CHECK Constraint
In SQL, One such constraint is the CHECK constraint, which allows to enforcement of domain integrity by limiting the values that can be inserted or updated in a column. By using CHECK, we can define conditions on a column’s values and ensure that they adhere to specific rules. In this article, we wi
5 min read
SQL | DEFAULT Constraint
In SQL, maintaining data integrity and ensuring consistency across tables is important for effective database management. One way to achieve this is by using constraints. Among the many types of constraints, the DEFAULT constraint plays an important role in automating data insertion and ensuring tha
3 min read
SQL Joining Data
SQL Joins (Inner, Left, Right and Full Join)
SQL joins are the foundation of database management systems, enabling the combination of data from multiple tables based on relationships between columns. Joins allow efficient data retrieval, which is essential for generating meaningful observations and solving complex business queries. Understandi
6 min read
SQL Outer Join
SQL Outer Joins allow retrieval of rows from two or more tables based on a related column. Unlike inner Joins, they also include rows that do not have a corresponding match in one or both of the tables. This capability makes Outer Joins extremely useful for comprehensive data analysis and reporting,
4 min read
SQL LEFT JOIN
In SQL, LEFT JOIN allows to retrieval of all records from the left table and only the matching records from the right table. When there is no matching record in the right table, SQL will return NULL for columns from the right table. This makes LEFT JOIN extremely useful for queries where you need to
4 min read
SQL RIGHT JOIN
In SQL, the RIGHT JOIN (also called RIGHT OUTER JOIN) is an essential command used to combine data from two tables based on a related column. It returns all records from the right table, along with the matching records from the left table. If there is no matching record in the left table, SQL will r
4 min read
SQL FULL JOIN
In SQL, the FULL JOIN (or FULL OUTER JOIN) is a powerful technique used to combine records from two or more tables. Unlike an INNER JOIN, which only returns rows where there are matches in both tables, a FULL JOIN retrieves all rows from both tables, filling in NULL values where matches do not exist
4 min read
SQL CROSS JOIN
In SQL, the CROSS JOIN is a unique join operation that returns the Cartesian product of two or more tables. This means it matches each row from the left table with every row from the right table, resulting in a combination of all possible pairs of records. In this article, we will learn the CROSS JO
3 min read
SQL Self Join
A Self Join in SQL is a powerful technique that allows one to join a table with itself. This operation is helpful when you need to compare rows within the same table based on specific conditions. A Self Join is often used in scenarios where there is hierarchical or relational data within the same ta
4 min read
SQL | UPDATE with JOIN
In SQL, the UPDATE with JOIN statement is a powerful tool that allows updating one table using data from another table based on a specific JOIN condition. This technique is particularly useful when we need to synchronize data, merge records, or update specific columns in one table by referencing rel
4 min read
SQL DELETE JOIN
The SQL DELETE JOIN statement is a powerful feature that allows us to delete rows from one table based on conditions related to another table. This is particularly useful when managing relationships between tables in a database. For example, we may want to delete rows in a "Library Books" table wher
4 min read
Recursive Join in SQL
In SQL, a recursive join is a powerful technique used to handle hierarchical data relationships, such as managing employee-manager relationships, family trees, or any data with a self-referential structure. This type of join enables us to combine data from the same table repeatedly, accumulating rec
3 min read
SQL Functions
SQL Date and Time Functions
Handling date and time data in SQL is essential for many database operations. SQL provides a variety of date and time functions that help users work with date values, perform calculations, and format them as needed. Whether you’re adding intervals to dates, extracting parts of a date, or formatting
4 min read
SQL | String functions
SQL String Functions are powerful tools that allow you to manipulate, format, and extract specific parts of text data in your database. These functions are essential for tasks like cleaning up data, comparing strings, and combining text fields. Whether you're working with names, addresses, or any fo
5 min read
SQL | Numeric Functions
SQL Numeric Functions are essential tools for performing mathematical and arithmetic operations on numeric data. These functions allow you to manipulate numbers, perform calculations, and aggregate data for reporting and analysis purposes. Understanding how to use SQL numeric functions is important
4 min read
SQL - Statistical Functions
SQL statistical functions are essential tools for extracting meaningful insights from databases. These functions, enable users to perform statistical calculations on numeric data. Whether determining averages, sums, counts, or measures of variability, these functions empower efficient data analysis
4 min read
Working With JSON in SQL
JSON stands for Javascript Object Notation. It is mainly used in storing and transporting data. Mostly all NoSQL databases like MongoDB, CouchDB, etc., use JSON format data. Whenever your data from one server has to be transferred to a web page, JSON format is the preferred format for front-end appl
7 min read
Conversion Function in SQL
In SQL data type conversion is important for effective database management and accurate query results. Data type conversion ensures that data from different sources or columns can be correctly interpreted and manipulated, especially when dealing with different formats like numbers, text, dates, and
5 min read
SQL Data Types
SQL Data Types are the pillar of relational database schema design. It ensures that data is stored efficiently and accurately. Data types define the type of value a column can hold, such as numbers, text, or dates. Understanding SQL Data Types is critical for database administrators, developers, and
5 min read
SQL LTRIM() Function
The SQL LTRIM() function is an essential tool used in data cleaning and manipulation tasks. This function helps remove unwanted leading spaces or specific characters from the left side of a string or string expression. It's commonly used to tidy up data by eliminating unnecessary spaces or character
4 min read
SQL UPPER() Function
In SQL, the UPPER() function is one of the most commonly used string functions. It is used to convert all characters in a given string to uppercase. Whether we are dealing with textual data that requires uniform formatting or need to compare strings without case sensitivity, the UPPER() function com
4 min read
SQL RTRIM() Function
SQL RTRIM function is a string function that removes spaces from the right side of a character or string. RTRIM or Right Trim function is used in data cleaning and manipulation in SQL. In this example, we will learn the basics of the RTRIM function, and learn how it works with examples of different
4 min read
SQL Miscellaneous Topics
SQL Wildcard Characters
SQL wildcard characters are special symbols used in SQL queries to search for specific patterns within string data. These characters are particularly effective in the LIKE and NOT LIKE clauses, allowing for filtering results based on partial matches. In this article, We will learn about SQL Wildcard
3 min read
SQL Comments
SQL Comments explain sections of SQL statements or prevent SQL statements from being executed. There are 3 types of comments in SQL: Single-line commentsMulti-line commentsIn-line commentsThese are the three commenting methods in SQL, each with its unique use. Let's discuss these SQL comments in det
3 min read
Pivot and Unpivot in SQL
In SQL, Pivot and Unpivot are relational operators that are used to transform one table into another in order to achieve more simpler view of table. Conventionally we can say that Pivot operator converts the rows data of the table into the column data. The Unpivot operator does the opposite that is
2 min read
SQL Injection
SQL Injection is a security flaw in web applications where attackers insert harmful SQL code through user inputs. This can allow them to access sensitive data, change database contents or even take control of the system. It's important to know about SQL Injection to keep web applications secure. In
7 min read
SQL Performance Tuning
SQL Performance tuning is the process of enhancing SQL queries to speed up the server performance. Performance tuning in SQL shortens the time it takes for a user to receive a response after sending a query and utilizes fewer resources in the process. The idea is that users can occasionally produce
10 min read
SQL Stored Procedures
A stored procedure in SQL is a group of SQL queries that can be saved and reused multiple times. It is very useful as it reduces the need for rewriting SQL queries. It enhances efficiency, reusability, and security in database management. Users can also pass parameters to stored procedures so that t
4 min read
SQL TRANSACTIONS
Transactions group a set of tasks into a single execution unit. Each transaction begins with a specific job and ends when all the tasks in the group successfully completed. If any of the tasks fail, the transaction fails. Therefore, a transaction has only two results: success or failure. Example of
4 min read
SQL | Subquery
In SQL, subqueries are one of the most powerful and flexible tools for writing efficient queries. A subquery is essentially a query nested within another query, allowing users to perform operations that depend on the results of another query. This makes it invaluable for tasks such as filtering, cal
4 min read
SQL | SEQUENCES
SQL sequences specifies the properties of a sequence object while creating it. An object bound to a user-defined schema called a sequence produces a series of numerical values in accordance with the specification used to create it. The series of numerical values can be configured to restart (cycle)
5 min read
SQL Auto Increment
In SQL databases, a primary key is important for uniquely identifying records in a table. However, sometimes it is not practical to manually assign unique values for each record, especially when handling large datasets. To simplify this process, SQL databases offer an Auto Increment feature that aut
7 min read
Window Functions in SQL
SQL window functions are an essential tool for database management and data analysis. They allow users to perform advanced calculations across a specified set of rows known as a "window" while retaining the individual data rows. Unlike traditional aggregate functions that return a single result for
5 min read
How to Get Current Date and Time in SQL?
Managing date and time efficiently is crucial for any database system. SQL provides built-in functions to retrieve the current date and time, which are especially useful for applications involving logging, reporting, and auditing. In this article, we will explain the three main SQL functions to fetc
4 min read
What is Cursor in SQL ?
Cursor is a Temporary Memory or Temporary Work Station. It is Allocated by Database Server at the Time of Performing DML(Data Manipulation Language) operations on the Table by the User. Cursors are used to store Database Tables. There are 2 types of Cursors: Implicit Cursors, and Explicit Cursors. T
6 min read
CTE in SQL
In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
5 min read
Dynamic SQL
Prerequisite - Difference between Static and Dynamic SQL Dynamic SQL is a programming technique that could be used to write SQL queries during runtime. Dynamic SQL could be used to create general and flexible SQL queries. Syntax for dynamic SQL is to make it string as below : 'SELECT statement'; To
2 min read
SQL Interview Questions
SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM Computer Scientists in the 1970s. By executing queries, SQL can create, update, delete, and retrieve data in databases like MySQL, Oracle, Postg
15+ min read