SQL Interview Qns-4
SQL Interview Qns-4
SQL (Structured Query Language) , that helps to manipulate and manage data in
relational databases.
SQL is used to communicate and connect with a database to create, modify,
retrieve, and delete data.
2) what is data ?
Data is a collection of information.
It can be used in a variety of forms like text, numbers, media, bytes, etc.
4)what is database ?
A database is an organized collection of data, so that it can be easily
accessed and managed.
5) what is DBMS ?
In DBMS, data is generally stored in either a hierarchical form or a
navigational form.
6) what is RDBMS ?
In RDBMS, the tables have an unique identifier called primary key and the
data values are stored in the form of tables.
Natural Join -> Returns records that have matching values in both
tables without ON Clause
(Inner) Join -> Returns records that have matching values in both
tables with ON Clauese
Left (Outer) Join -> Returns all records from the left table, and the
matched records from the right table
Right (Outer) Join -> Returns all records from the right table, and the
matched records from the left table
Self Join -> A self join is a regular join, but the table is joined
with itself.
Full (Outer) Join -> Returns all records when there is a match in either
left or right table
Cross Join -> The CROSS JOIN returns all matching records from both
tables whether the other table matches or not.
Joins every row of the first table to every row of the
second table
e.g., So, if there are rows in "Customers" that do not have
matches in "Orders", or if there are rows in "Orders" that
do not have matches in "Customers", those rows will be listed as well.
Uninon -> The UNION command combines the result set of two or more SELECT
statements. It will returns only distinct values.
Union all -> The UNION ALL command combines the result set of two or more
SELECT statements. It will allows duplicate values.
Abs,Sum,Avg,Count,Max,Min,Mod,Ceil/Ceiling,floor,round,Truncate,SQRT,POWER,.etc
String Functions -> In SQL String functions are the predefined functions that
allow the database users for string manipulation.
Insert,Concat,Mid,Substring,Substring_index,Mid,Len,Lower,Upper,Replace,Reverse,Lef
t,LTrim,Right,RTrim,Trim,.etc
Date Functions -> In SQL Date functions are the predefined functions
SELECT CURRENT_TIMESTAMP()/now();
select adddate("1998-05-21", interval 10000 day);
Datediff("1998-05-21", "2023-08-25")'
SELECT DAYNAME("2017-06-15");
SELECT Day/month/Year("2017-06-15");
45) What is the purpose of an index in SQL, and how does it work?
An index is used to improve the performance of queries by allowing for faster
data retrieval.
It creates a separate data structure that stores the values of one or more
columns .
Non-Clustered Index
A separate structure that contains the index key and a pointer to the data.
Multiple non-clustered indexes per table are possible.
Slower data retrieval for large data sets.
Does not contain the actual data
48) What is the difference between a function and a stored procedure in SQL?
In SQL, a function returns a value,
while a stored procedure does not necessarily return a value and may execute
a series of operations or tasks.
Benefits :-
Converting raw data into a usable form can be extremely time-consuming ,
so it makes sense to automate data crunching as much as possible using
programming languages or other tools
Technical :-
Find 2nd Highest Salary ?
SELECT MAX(salary) as second_highest_salary FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees)
Table Description:
Catalogue
Catalogue_Entry_id - Catalogue entry id
Parent_Catelogue_Entry_id - Parent catalogue id of sub items that are listed
Catalogue_Entry_Description - description of the entry
Sizes
Size_Code - size code
Size_Description - description of the size
Colors
Color_Code - color code
Color_Code_Description - description of the color
Products
Product_id - id of the product
Catalougue_Entry_id - entry id in the catalogue
Color_Code - color code of the product
Size_Code - size code of the product
Product_Price - price of the product
Product_Description - description of the product
1) On account of monsoon sale, the shop is giving a flat 5% discount for all the
Women Sportswear.
Get the list of all the products, old price and new price after applying the
discount.
(Use tables: - Catalogue, sizes, colors, products) (Marks - 2)
2) Get the list of all the catalogue descriptions where the average price of all
its products is greater than 1000.
(Use tables: - Catalogue, sizes, colors, products) (Marks - 2)