SQL Store
SQL Store
-->A stored procedure is a prepared SQL code that you can save, so the code can be
reused over and over again.
https://www.w3schools.com/sql/sql_stored_procedures.asp
If the SQL table has duplicate rows, the duplicate rows must be removed.
ID Name Age
1 A 21
2 B 23
2 B 23
4 D 22
5 E 25
6 G 26
5 E 25
The following SQL query removes the duplicate ids from the table:
Q19. Write the SQL query to get the third maximum salary of an employee from a
table named employees.
Employee table
employee_name salary
A 24000
C 34000
D 55000
E 75000
F 21000
G 40000
H 50000
SELECT * FROM(
WHERE r=&n;
Q7. What are some common clauses used with SELECT query in SQL?
The following are some frequent SQL clauses used in conjunction with a SELECT
query:
WHERE clause: In SQL, the WHERE clause is used to filter records that are required
depending on certain criteria.
ORDER BY clause: The ORDER BY clause in SQL is used to sort data in ascending (ASC)
or descending (DESC) order depending on specified field(s) (DESC).
GROUP BY clause: GROUP BY clause in SQL is used to group entries with identical
data and may be used with aggregation methods to obtain summarised database
results.
HAVING clause in SQL is used to filter records in combination with the GROUP BY
clause. It is different from WHERE, since the WHERE clause cannot filter aggregated
records.
A) CONCAT (joining two or more values): This function is used to join two or more
values together. The second string is always appended to the end of the first
string.
B) SUBSTR: This function returns a segment of a string from a given start point to
a given endpoint.
C) LENGTH: This function returns the length of the string in numerical form,
including blank spaces.
Q20. What is the difference between the RANK() and DENSE_RANK() functions?
The RANK() function in the result set defines the rank of each row within your
ordered partition. If both rows have the same rank,
the next number in the ranking will be the previous rank plus a number of
duplicates. If we have three records at rank 4, for example, the next level
indicated is 7.
The DENSE_RANK() function assigns a distinct rank to each row within a partition
based on the provided column value, with no gaps.
It always indicates a ranking in order of precedence. This function will assign the
same rank to the two rows if they have the same rank,
with the next rank being the next consecutive number. If we have three records at
rank 4, for example, the next level indicated is 5
G) TRIM: This function removes all defined characters from the beginning, end, or
both ends of a string. It also reduced the amount of wasted space.
SQL aggregate functions provide information about a database’s data. AVG, for
example, returns the average of a database column’s values.
SQL provides seven (7) aggregate functions, which are given below:
Q72. What are the syntax and use of the COALESCE function?
From a succession of expressions, the COALESCE function returns the first non-NULL
value. The expressions are evaluated in the order
that they are supplied, and the function’s result is the first non-null value. Only
if all of the inputs are null does the COALESCE method return NULL.