sql
sql
TRUNCATE command is used to delete all the rows from the table and free the space containing the
table.
DROP command is used to remove an object from the database. If you drop a table, all the rows in
the table are deleted and the table structure is removed from the database.
Write a SQL query to remove first 1000 records from table 'Temporary' based on 'id'.
Write a SQL statement to delete the table 'Temporary' while keeping its relations intact.
If a table is dropped, all things associated with the tables are dropped as well. This includes - the
relationships defined on the table with other tables, the integrity checks and constraints, access
privileges and other grants that the table has. To create and use the table again in its original form,
all these relations, checks, constraints, privileges and relationships need to be redefined. However, if
a table is truncated, none of the above problems exist and the table retains its original structure.
The TRUNCATE command is used to delete all the rows from the table and free the space containing
the table.
The DELETE command deletes only the rows from the table based on the condition given in the
where clause or deletes all the rows from the table if no condition is specified. But it does not free
the space containing the table.
An aggregate function performs operations on a collection of values to return a single scalar value.
Aggregate functions are often used with the GROUP BY and HAVING clauses of the SELECT statement.
Following are the widely used SQL aggregate functions:
Note: All aggregate functions described above ignore NULL values except for the COUNT function.
A scalar function returns a single value based on the input value. Following are the widely used SQL
scalar functions:
ROUND() - Calculates the round-off integer value for a numeric field (or decimal point
values).
------------------------------------------------------------------------------------------------------------------------------------
HAVING: Filters grouped data after the GROUP BY clause has been applied.
In short, WHERE applies to individual rows, while HAVING applies to groups.
);
sql
DENSE RANK
SELECT salary
FROM (
SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rank
FROM employees
) temp
WHERE rank = 2;
FROM customers
GROUP BY email
FROM contacts
FROM table_name;
https://www.baeldung.com/sql/identify-duplicate-values
EXCEL
you customize a message with the XLOOKUP function if the lookup value is not found,
VLOOKUP would give a wrong result if you add/delete a new column in your data
If speed is what you are looking for, INDEX/MATCH combo is the way to go.
If backward compatibility is required, INDEX + MATCH is the most flexible and powerful lookup
option available. XLOOK UP INTODUCED IN 2021
Reverse search. While INDEX MATCH can only look up from the beginning to the end, both XLOOKUP
and INDEX + XMATCH can search in both directions: from first to last and from last to first.
Handling errors. The INDEX MATCH combo does not have a built-in feature to handle errors. If the
formula cannot find a lookup value, it will show #N/A. On the other hand, XLOOKUP has an extra
argument (if_not_found) that lets you customize the response when there is no match. You can
provide a certain value, display a friendly message, or even execute another formula.
It can do both exact and approximate matches in any dataset, whereas INDEX MATCH is
limited to approximate matches in sorted data.
It may not be as flexible as INDEX MATCH for some scenarios, such as returning values from
non-contiguous columns.
It may not work well with large data sets or volatile formulas.