โจ๏ธ MongoDB Cheat Sheet
This Post includes a MongoDB cheat sheet to make it easy for our followers to work with MongoDB.
Working with databases
Working with rows
Working with Documents
Querying data from documents
Modifying data in documents
Searching
MongoDB is a flexible, document-orientated, NoSQL database program that can scale to any enterprise volume without compromising search performance.
This Post includes a MongoDB cheat sheet to make it easy for our followers to work with MongoDB.
Working with databases
Working with rows
Working with Documents
Querying data from documents
Modifying data in documents
Searching
โค3๐3
Top 5 SQL Functions
1. SELECT Statement:
- Function: Retrieving data from one or more tables.
- Example:
2. COUNT Function:
- Function: Counts the number of rows that meet a specified condition.
- Example:
3. SUM Function:
- Function: Calculates the sum of values in a numeric column.
- Example:
4. AVG Function:
- Function: Computes the average value of a numeric column.
- Example:
5. GROUP BY Clause:
- Function: Groups rows that have the same values in specified columns into summary rows.
- Example:
These functions are fundamental in SQL and are frequently used for various data manipulation tasks, including data retrieval, aggregation, and analysis.
1. SELECT Statement:
- Function: Retrieving data from one or more tables.
- Example:
SELECT column1, column2 FROM table WHERE condition;2. COUNT Function:
- Function: Counts the number of rows that meet a specified condition.
- Example:
SELECT COUNT(column) FROM table WHERE condition;3. SUM Function:
- Function: Calculates the sum of values in a numeric column.
- Example:
SELECT SUM(column) FROM table WHERE condition;4. AVG Function:
- Function: Computes the average value of a numeric column.
- Example:
SELECT AVG(column) FROM table WHERE condition;5. GROUP BY Clause:
- Function: Groups rows that have the same values in specified columns into summary rows.
- Example:
SELECT column, AVG(numeric_column) FROM table GROUP BY column;These functions are fundamental in SQL and are frequently used for various data manipulation tasks, including data retrieval, aggregation, and analysis.
๐3
SQL (Structured Query Language), which is used to manage and manipulate relational databases.
Here's a beginner-friendly introduction:
SELECT columns
FROM table
WHERE condition;
The SELECT statement retrieves data from a table
SELECT * FROM customers;
--This retrieves all columns from the "customers" table.
You can use the WHERE clause to filter rows based on conditions.
To limit the number of rows returned, you can use the LIMIT clause.
--This retrieves the first 10 rows from the "products" table.
Use the ORDER BY clause to sort the results in ascending or descending order.
The INSERT INTO statement adds new records to a table
INSERT INTO employees (first_name, last_name) VALUES ('John', 'Doe');
--This inserts a new employee named John Doe into the "employees" table.
The UPDATE statement modifies existing records in a table.
UPDATE customers SET email = '[email protected]' WHERE customer_id = 123;
--This updates the email address for the customer with ID 123.
Joins allow you to combine data from multiple tables based on related columns
React โค๏ธ for more
Here's a beginner-friendly introduction:
SELECT columns
FROM table
WHERE condition;
The SELECT statement retrieves data from a table
SELECT * FROM customers;
--This retrieves all columns from the "customers" table.
You can use the WHERE clause to filter rows based on conditions.
To limit the number of rows returned, you can use the LIMIT clause.
--This retrieves the first 10 rows from the "products" table.
Use the ORDER BY clause to sort the results in ascending or descending order.
The INSERT INTO statement adds new records to a table
INSERT INTO employees (first_name, last_name) VALUES ('John', 'Doe');
--This inserts a new employee named John Doe into the "employees" table.
The UPDATE statement modifies existing records in a table.
UPDATE customers SET email = '[email protected]' WHERE customer_id = 123;
--This updates the email address for the customer with ID 123.
Joins allow you to combine data from multiple tables based on related columns
React โค๏ธ for more
โค2๐1
What's the ONE skill you absolutely NEED to master in 2025 to stay ahead of the curve?
๐ค The latest video dives deep into the MOST in-demand skill this year.
Watch Now: https://youtu.be/GuQHC2_pPxc?feature=shared
And trust me, you won't want to miss this!
Register Now: https://surl.li/bbkbvd
๐ค The latest video dives deep into the MOST in-demand skill this year.
Watch Now: https://youtu.be/GuQHC2_pPxc?feature=shared
And trust me, you won't want to miss this!
Register Now: https://surl.li/bbkbvd
๐3
Quick SQL functions cheat sheet for beginners
Aggregate Functions
COUNT(*): Counts rows.
SUM(column): Total sum.
AVG(column): Average value.
MAX(column): Maximum value.
MIN(column): Minimum value.
String Functions
CONCAT(a, b, โฆ): Concatenates strings.
SUBSTRING(s, start, length): Extracts part of a string.
UPPER(s) / LOWER(s): Converts string case.
TRIM(s): Removes leading/trailing spaces.
Date & Time Functions
CURRENT_DATE / CURRENT_TIME / CURRENT_TIMESTAMP: Current date/time.
EXTRACT(unit FROM date): Retrieves a date part (e.g., year, month).
DATE_ADD(date, INTERVAL n unit): Adds an interval to a date.
Numeric Functions
ROUND(num, decimals): Rounds to a specified decimal.
CEIL(num) / FLOOR(num): Rounds up/down.
ABS(num): Absolute value.
MOD(a, b): Returns the remainder.
Control Flow Functions
CASE: Conditional logic.
COALESCE(val1, val2, โฆ): Returns the first non-null value.
Like for more free Cheatsheets โค๏ธ
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
#dataanalytics
Aggregate Functions
COUNT(*): Counts rows.
SUM(column): Total sum.
AVG(column): Average value.
MAX(column): Maximum value.
MIN(column): Minimum value.
String Functions
CONCAT(a, b, โฆ): Concatenates strings.
SUBSTRING(s, start, length): Extracts part of a string.
UPPER(s) / LOWER(s): Converts string case.
TRIM(s): Removes leading/trailing spaces.
Date & Time Functions
CURRENT_DATE / CURRENT_TIME / CURRENT_TIMESTAMP: Current date/time.
EXTRACT(unit FROM date): Retrieves a date part (e.g., year, month).
DATE_ADD(date, INTERVAL n unit): Adds an interval to a date.
Numeric Functions
ROUND(num, decimals): Rounds to a specified decimal.
CEIL(num) / FLOOR(num): Rounds up/down.
ABS(num): Absolute value.
MOD(a, b): Returns the remainder.
Control Flow Functions
CASE: Conditional logic.
COALESCE(val1, val2, โฆ): Returns the first non-null value.
Like for more free Cheatsheets โค๏ธ
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
#dataanalytics
๐3๐2โค1
SQL Joins โ Essential Concepts ๐
1๏ธโฃ What Are SQL Joins?
SQL Joins are used to combine rows from two or more tables based on a related column.
2๏ธโฃ Types of Joins
INNER JOIN: Returns only matching rows from both tables.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id;
LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table and matching rows from the right table.
SELECT * FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id;
RIGHT JOIN (RIGHT OUTER JOIN): Returns all rows from the right table and matching rows from the left table.
SELECT * FROM TableA RIGHT JOIN TableB ON TableA.id = TableB.id;
FULL JOIN (FULL OUTER JOIN): Returns all rows when there is a match in either table.
SELECT * FROM TableA FULL JOIN TableB ON TableA.id = TableB.id;
3๏ธโฃ Self Join
A table joins with itself to compare rows.
SELECT A.name, B.name FROM Employees A JOIN Employees B ON A.manager_id = B.id;
4๏ธโฃ Cross Join
Returns the Cartesian product of both tables (every row from Table A pairs with every row from Table B).
SELECT * FROM TableA CROSS JOIN TableB;
5๏ธโฃ Joins with Multiple Conditions
Using multiple columns for matching.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id AND TableA.type = TableB.type;
6๏ธโฃ Using Aliases in Joins
Shortens table names for better readability.
SELECT A.name, B.salary FROM Employees A INNER JOIN Salaries B ON A.id = B.emp_id;
7๏ธโฃ Handling NULLs in Joins
Use COALESCE(column, default_value) to replace NULL values.
IS NULL to filter unmatched rows in LEFT or RIGHT JOINs.
Free SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
React with โค๏ธ for free resources
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
1๏ธโฃ What Are SQL Joins?
SQL Joins are used to combine rows from two or more tables based on a related column.
2๏ธโฃ Types of Joins
INNER JOIN: Returns only matching rows from both tables.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id;
LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table and matching rows from the right table.
SELECT * FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id;
RIGHT JOIN (RIGHT OUTER JOIN): Returns all rows from the right table and matching rows from the left table.
SELECT * FROM TableA RIGHT JOIN TableB ON TableA.id = TableB.id;
FULL JOIN (FULL OUTER JOIN): Returns all rows when there is a match in either table.
SELECT * FROM TableA FULL JOIN TableB ON TableA.id = TableB.id;
3๏ธโฃ Self Join
A table joins with itself to compare rows.
SELECT A.name, B.name FROM Employees A JOIN Employees B ON A.manager_id = B.id;
4๏ธโฃ Cross Join
Returns the Cartesian product of both tables (every row from Table A pairs with every row from Table B).
SELECT * FROM TableA CROSS JOIN TableB;
5๏ธโฃ Joins with Multiple Conditions
Using multiple columns for matching.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id AND TableA.type = TableB.type;
6๏ธโฃ Using Aliases in Joins
Shortens table names for better readability.
SELECT A.name, B.salary FROM Employees A INNER JOIN Salaries B ON A.id = B.emp_id;
7๏ธโฃ Handling NULLs in Joins
Use COALESCE(column, default_value) to replace NULL values.
IS NULL to filter unmatched rows in LEFT or RIGHT JOINs.
Free SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
React with โค๏ธ for free resources
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
๐5
10 SQL Concepts Every Data Analyst Should Master ๐
โ SELECT, WHERE, ORDER BY โ Core of querying your data
โ JOINs (INNER, LEFT, RIGHT, FULL) โ Combine data from multiple tables
โ GROUP BY & HAVING โ Aggregate and filter grouped data
โ Subqueries โ Nest queries inside queries for complex logic
โ CTEs (Common Table Expressions) โ Write cleaner, reusable SQL logic
โ Window Functions โ Perform advanced analytics like rankings & running totals
โ Indexes โ Boost your query performance
โ Normalization โ Structure your database efficiently
โ UNION vs UNION ALL โ Combine result sets with or without duplicates
โ Stored Procedures & Functions โ Reusable logic inside your DB
React with โค๏ธ if you want me to cover each topic in detail
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
โ SELECT, WHERE, ORDER BY โ Core of querying your data
โ JOINs (INNER, LEFT, RIGHT, FULL) โ Combine data from multiple tables
โ GROUP BY & HAVING โ Aggregate and filter grouped data
โ Subqueries โ Nest queries inside queries for complex logic
โ CTEs (Common Table Expressions) โ Write cleaner, reusable SQL logic
โ Window Functions โ Perform advanced analytics like rankings & running totals
โ Indexes โ Boost your query performance
โ Normalization โ Structure your database efficiently
โ UNION vs UNION ALL โ Combine result sets with or without duplicates
โ Stored Procedures & Functions โ Reusable logic inside your DB
React with โค๏ธ if you want me to cover each topic in detail
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
โค2
SQL Cheatsheet ๐
This SQL cheatsheet is designed to be your quick reference guide for SQL programming. Whether youโre a beginner learning how to query databases or an experienced developer looking for a handy resource, this cheatsheet covers essential SQL topics.
1. Database Basics
-
-
2. Tables
- Create Table:
- Drop Table:
- Alter Table:
3. Insert Data
-
4. Select Queries
- Basic Select:
- Select Specific Columns:
- Select with Condition:
5. Update Data
-
6. Delete Data
-
7. Joins
- Inner Join:
- Left Join:
- Right Join:
8. Aggregations
- Count:
- Sum:
- Group By:
9. Sorting & Limiting
- Order By:
- Limit Results:
10. Indexes
- Create Index:
- Drop Index:
11. Subqueries
-
12. Views
- Create View:
- Drop View:
Here you can find SQL Interview Resources๐
https://t.iss.one/DataSimplifier
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
This SQL cheatsheet is designed to be your quick reference guide for SQL programming. Whether youโre a beginner learning how to query databases or an experienced developer looking for a handy resource, this cheatsheet covers essential SQL topics.
1. Database Basics
-
CREATE DATABASE db_name;-
USE db_name;2. Tables
- Create Table:
CREATE TABLE table_name (col1 datatype, col2 datatype);- Drop Table:
DROP TABLE table_name;- Alter Table:
ALTER TABLE table_name ADD column_name datatype;3. Insert Data
-
INSERT INTO table_name (col1, col2) VALUES (val1, val2);4. Select Queries
- Basic Select:
SELECT * FROM table_name;- Select Specific Columns:
SELECT col1, col2 FROM table_name;- Select with Condition:
SELECT * FROM table_name WHERE condition;5. Update Data
-
UPDATE table_name SET col1 = value1 WHERE condition;6. Delete Data
-
DELETE FROM table_name WHERE condition;7. Joins
- Inner Join:
SELECT * FROM table1 INNER JOIN table2 ON table1.col = table2.col;- Left Join:
SELECT * FROM table1 LEFT JOIN table2 ON table1.col = table2.col;- Right Join:
SELECT * FROM table1 RIGHT JOIN table2 ON table1.col = table2.col;8. Aggregations
- Count:
SELECT COUNT(*) FROM table_name;- Sum:
SELECT SUM(col) FROM table_name;- Group By:
SELECT col, COUNT(*) FROM table_name GROUP BY col;9. Sorting & Limiting
- Order By:
SELECT * FROM table_name ORDER BY col ASC|DESC;- Limit Results:
SELECT * FROM table_name LIMIT n;10. Indexes
- Create Index:
CREATE INDEX idx_name ON table_name (col);- Drop Index:
DROP INDEX idx_name;11. Subqueries
-
SELECT * FROM table_name WHERE col IN (SELECT col FROM other_table);12. Views
- Create View:
CREATE VIEW view_name AS SELECT * FROM table_name;- Drop View:
DROP VIEW view_name;Here you can find SQL Interview Resources๐
https://t.iss.one/DataSimplifier
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
โค2๐1
Hey guys,
Today, letโs talk about SQL conceptual questions that are often asked in data analyst interviews. These questions test not only your technical skills but also your conceptual understanding of SQL and its real-world applications.
1. What is the difference between SQL and NoSQL?
- SQL (Structured Query Language) is a relational database management system, meaning it uses tables (rows and columns) to store data.
- NoSQL databases, on the other hand, handle unstructured data and donโt rely on a schema, making them more flexible in terms of data storage and retrieval.
- Interview Tip: Don't just memorize definitions. Be prepared to explain scenarios where youโd use SQL over NoSQL, and vice versa.
2. What is the difference between INNER JOIN and OUTER JOIN?
- An INNER JOIN returns records that have matching values in both tables.
- An OUTER JOIN returns all records from one table and the matched records from the second table. If there's no match, NULL values are returned.
3. How do you optimize a SQL query for better performance?
- Indexing: Create indexes on columns used frequently in WHERE, JOIN, or GROUP BY clauses.
- Query optimization: Use appropriate WHERE clauses to reduce the data set and avoid unnecessary calculations.
- Avoid SELECT *: Always specify the columns you need to reduce the amount of data retrieved.
- Limit results: If you only need a subset of the data, use the LIMIT clause.
4. What are the different types of SQL constraints?
Constraints are used to enforce rules on data in a table. They ensure the accuracy and reliability of the data. The most common types are:
- PRIMARY KEY: Ensures each record is unique and not null.
- FOREIGN KEY: Enforces a relationship between two tables.
- UNIQUE: Ensures all values in a column are unique.
- NOT NULL: Prevents NULL values from being entered into a column.
- CHECK: Ensures a column's values meet a specific condition.
5. What is normalization? What are the different normal forms?
Normalization is the process of organizing data to reduce redundancy and improve data integrity. Hereโs a quick overview of normal forms:
- 1NF (First Normal Form): Ensures that all values in a table are atomic (indivisible).
- 2NF (Second Normal Form): Ensures that the table is in 1NF and that all non-key columns are fully dependent on the primary key.
- 3NF (Third Normal Form): Ensures that the table is in 2NF and all columns are independent of each other except for the primary key.
6. What is a subquery?
A subquery is a query within another query. It's used to perform operations that need intermediate results before generating the final query.
Example:
In this case, the subquery calculates the average salary, and the outer query selects employees whose salary is greater than the average.
7. What is the difference between a UNION and a UNION ALL?
- UNION combines the result sets of two SELECT statements and removes duplicates.
- UNION ALL combines the result sets and includes duplicates.
8. What is the difference between WHERE and HAVING clause?
- WHERE filters rows before any groupings are made. Itโs used with SELECT, INSERT, UPDATE, or DELETE statements.
- HAVING filters groups after the GROUP BY clause.
9. How would you handle NULL values in SQL?
NULL values can represent missing or unknown data. Hereโs how to manage them:
- Use IS NULL or IS NOT NULL in WHERE clauses to filter null values.
- Use COALESCE() or IFNULL() to replace NULL values with default ones.
Example:
10. What is the purpose of the GROUP BY clause?
The GROUP BY clause groups rows with the same values into summary rows. Itโs often used with aggregate functions like COUNT, SUM, AVG, etc.
Example:
Here you can find SQL Interview Resources๐
https://t.iss.one/DataSimplifier
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
Today, letโs talk about SQL conceptual questions that are often asked in data analyst interviews. These questions test not only your technical skills but also your conceptual understanding of SQL and its real-world applications.
1. What is the difference between SQL and NoSQL?
- SQL (Structured Query Language) is a relational database management system, meaning it uses tables (rows and columns) to store data.
- NoSQL databases, on the other hand, handle unstructured data and donโt rely on a schema, making them more flexible in terms of data storage and retrieval.
- Interview Tip: Don't just memorize definitions. Be prepared to explain scenarios where youโd use SQL over NoSQL, and vice versa.
2. What is the difference between INNER JOIN and OUTER JOIN?
- An INNER JOIN returns records that have matching values in both tables.
- An OUTER JOIN returns all records from one table and the matched records from the second table. If there's no match, NULL values are returned.
3. How do you optimize a SQL query for better performance?
- Indexing: Create indexes on columns used frequently in WHERE, JOIN, or GROUP BY clauses.
- Query optimization: Use appropriate WHERE clauses to reduce the data set and avoid unnecessary calculations.
- Avoid SELECT *: Always specify the columns you need to reduce the amount of data retrieved.
- Limit results: If you only need a subset of the data, use the LIMIT clause.
4. What are the different types of SQL constraints?
Constraints are used to enforce rules on data in a table. They ensure the accuracy and reliability of the data. The most common types are:
- PRIMARY KEY: Ensures each record is unique and not null.
- FOREIGN KEY: Enforces a relationship between two tables.
- UNIQUE: Ensures all values in a column are unique.
- NOT NULL: Prevents NULL values from being entered into a column.
- CHECK: Ensures a column's values meet a specific condition.
5. What is normalization? What are the different normal forms?
Normalization is the process of organizing data to reduce redundancy and improve data integrity. Hereโs a quick overview of normal forms:
- 1NF (First Normal Form): Ensures that all values in a table are atomic (indivisible).
- 2NF (Second Normal Form): Ensures that the table is in 1NF and that all non-key columns are fully dependent on the primary key.
- 3NF (Third Normal Form): Ensures that the table is in 2NF and all columns are independent of each other except for the primary key.
6. What is a subquery?
A subquery is a query within another query. It's used to perform operations that need intermediate results before generating the final query.
Example:
SELECT employee_id, name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
In this case, the subquery calculates the average salary, and the outer query selects employees whose salary is greater than the average.
7. What is the difference between a UNION and a UNION ALL?
- UNION combines the result sets of two SELECT statements and removes duplicates.
- UNION ALL combines the result sets and includes duplicates.
8. What is the difference between WHERE and HAVING clause?
- WHERE filters rows before any groupings are made. Itโs used with SELECT, INSERT, UPDATE, or DELETE statements.
- HAVING filters groups after the GROUP BY clause.
9. How would you handle NULL values in SQL?
NULL values can represent missing or unknown data. Hereโs how to manage them:
- Use IS NULL or IS NOT NULL in WHERE clauses to filter null values.
- Use COALESCE() or IFNULL() to replace NULL values with default ones.
Example:
SELECT name, COALESCE(age, 0) AS age
FROM employees;
10. What is the purpose of the GROUP BY clause?
The GROUP BY clause groups rows with the same values into summary rows. Itโs often used with aggregate functions like COUNT, SUM, AVG, etc.
Example:
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
Here you can find SQL Interview Resources๐
https://t.iss.one/DataSimplifier
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
๐4โค2๐1
SQL Advanced Concepts for Data Analyst Interviews
1. Window Functions: Gain proficiency in window functions like
2. Common Table Expressions (CTEs): Understand how to use CTEs with the
3. Recursive CTEs: Learn how to use recursive CTEs to solve hierarchical or recursive data problems, such as navigating organizational charts or bill-of-materials structures.
4. Advanced Joins: Master complex join techniques, including self-joins (joining a table with itself), cross joins (Cartesian product), and using multiple joins in a single query.
5. Subqueries and Correlated Subqueries: Be adept at writing subqueries that return a single value or a set of values. Correlated subqueries, which reference columns from the outer query, are particularly powerful for row-by-row operations.
6. Indexing Strategies: Learn advanced indexing strategies, such as covering indexes, composite indexes, and partial indexes. Understand how to optimize query performance by designing the right indexes and when to use
7. Query Optimization and Execution Plans: Develop skills in reading and interpreting SQL execution plans to understand how queries are executed. Use tools like
8. Stored Procedures: Understand how to create and use stored procedures to encapsulate complex SQL logic into reusable, modular code. Learn how to pass parameters, handle errors, and return multiple result sets from a stored procedure.
9. Triggers: Learn how to create triggers to automatically execute a specified action in response to certain events on a table (e.g.,
10. Transactions and Isolation Levels: Master the use of transactions to ensure that a series of SQL operations are executed as a single unit of work. Understand different isolation levels (
11. PIVOT and UNPIVOT: Use the
12. Dynamic SQL: Learn how to write dynamic SQL queries that are constructed and executed at runtime. This is useful when the exact SQL query cannot be determined until runtime, such as in scenarios involving user-defined filters or conditional logic.
13. Data Partitioning: Understand how to implement data partitioning strategies, such as range partitioning or list partitioning, to manage large tables efficiently. Partitioning can significantly improve query performance and manageability.
14. Temporary Tables: Learn how to create and use temporary tables to store intermediate results within a session. Understand the differences between local and global temporary tables, and when to use them.
15. Materialized Views: Use materialized views to store the result of a query physically and update it periodically. This can drastically improve performance for complex queries that need to be executed frequently.
16. Handling Complex Data Types: Understand how to work with complex data types such as JSON, XML, and arrays. Learn how to store, query, and manipulate these types in SQL databases, including using functions like
Here you can find SQL Interview Resources๐
https://t.iss.one/DataSimplifier
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
1. Window Functions: Gain proficiency in window functions like
ROW_NUMBER(), RANK(), DENSE_RANK(), NTILE(), and LAG()/LEAD(). These functions allow you to perform calculations across a set of table rows related to the current row without collapsing the result set into a single output.2. Common Table Expressions (CTEs): Understand how to use CTEs with the
WITH clause to create temporary result sets that can be referenced within a SELECT, INSERT, UPDATE, or DELETE statement. CTEs improve the readability and maintainability of complex queries.3. Recursive CTEs: Learn how to use recursive CTEs to solve hierarchical or recursive data problems, such as navigating organizational charts or bill-of-materials structures.
4. Advanced Joins: Master complex join techniques, including self-joins (joining a table with itself), cross joins (Cartesian product), and using multiple joins in a single query.
5. Subqueries and Correlated Subqueries: Be adept at writing subqueries that return a single value or a set of values. Correlated subqueries, which reference columns from the outer query, are particularly powerful for row-by-row operations.
6. Indexing Strategies: Learn advanced indexing strategies, such as covering indexes, composite indexes, and partial indexes. Understand how to optimize query performance by designing the right indexes and when to use
CLUSTERED versus NON-CLUSTERED indexes.7. Query Optimization and Execution Plans: Develop skills in reading and interpreting SQL execution plans to understand how queries are executed. Use tools like
EXPLAIN or EXPLAIN ANALYZE to identify performance bottlenecks and optimize query performance.8. Stored Procedures: Understand how to create and use stored procedures to encapsulate complex SQL logic into reusable, modular code. Learn how to pass parameters, handle errors, and return multiple result sets from a stored procedure.
9. Triggers: Learn how to create triggers to automatically execute a specified action in response to certain events on a table (e.g.,
AFTER INSERT, BEFORE UPDATE). Triggers are useful for maintaining data integrity and automating workflows.10. Transactions and Isolation Levels: Master the use of transactions to ensure that a series of SQL operations are executed as a single unit of work. Understand different isolation levels (
READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE) and their impact on data consistency and concurrency.11. PIVOT and UNPIVOT: Use the
PIVOT operator to transform row data into columnar data and UNPIVOT to convert columns back into rows. These operations are crucial for reshaping data for reporting and analysis.12. Dynamic SQL: Learn how to write dynamic SQL queries that are constructed and executed at runtime. This is useful when the exact SQL query cannot be determined until runtime, such as in scenarios involving user-defined filters or conditional logic.
13. Data Partitioning: Understand how to implement data partitioning strategies, such as range partitioning or list partitioning, to manage large tables efficiently. Partitioning can significantly improve query performance and manageability.
14. Temporary Tables: Learn how to create and use temporary tables to store intermediate results within a session. Understand the differences between local and global temporary tables, and when to use them.
15. Materialized Views: Use materialized views to store the result of a query physically and update it periodically. This can drastically improve performance for complex queries that need to be executed frequently.
16. Handling Complex Data Types: Understand how to work with complex data types such as JSON, XML, and arrays. Learn how to store, query, and manipulate these types in SQL databases, including using functions like
JSON_EXTRACT(), XMLQUERY(), or array functions.Here you can find SQL Interview Resources๐
https://t.iss.one/DataSimplifier
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
โค4๐2๐1
If youโre a Data Analyst, chances are you use ๐๐๐ every single day. And if youโre preparing for interviews, youโve probably realized that it's not just about writing queries it's about writing smart, efficient, and scalable ones.
1. ๐๐ซ๐๐๐ค ๐๐ญ ๐๐จ๐ฐ๐ง ๐ฐ๐ข๐ญ๐ก ๐๐๐๐ฌ (๐๐จ๐ฆ๐ฆ๐จ๐ง ๐๐๐๐ฅ๐ ๐๐ฑ๐ฉ๐ซ๐๐ฌ๐ฌ๐ข๐จ๐ง๐ฌ)
Ever worked on a query that became an unreadable monster? CTEs let you break that down into logical steps. You can treat them like temporary views โ great for simplifying logic and improving collaboration across your team.
2. ๐๐ฌ๐ ๐๐ข๐ง๐๐จ๐ฐ ๐ ๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐ฌ
Forget the mess of subqueries. With functions like ROW_NUMBER(), RANK(), LEAD() and LAG(), you can compare rows, rank items, or calculate running totals โ all within the same query. Total
3. ๐๐ฎ๐๐ช๐ฎ๐๐ซ๐ข๐๐ฌ (๐๐๐ฌ๐ญ๐๐ ๐๐ฎ๐๐ซ๐ข๐๐ฌ)
Yes, they're old school, but nested subqueries are still powerful. Use them when you want to filter based on results of another query or isolate logic step-by-step before joining with the big picture.
4. ๐๐ง๐๐๐ฑ๐๐ฌ & ๐๐ฎ๐๐ซ๐ฒ ๐๐ฉ๐ญ๐ข๐ฆ๐ข๐ณ๐๐ญ๐ข๐จ๐ง
Query taking forever? Look at your indexes. Index the columns you use in JOINs, WHERE, and GROUP BY. Even basic knowledge of how the SQL engine reads data can take your skills up a notch.
5. ๐๐จ๐ข๐ง๐ฌ ๐ฏ๐ฌ. ๐๐ฎ๐๐ช๐ฎ๐๐ซ๐ข๐๐ฌ
Joins are usually faster and better for combining large datasets. Subqueries, on the other hand, are cleaner when doing one-off filters or smaller operations. Choose wisely based on the context.
6. ๐๐๐๐ ๐๐ญ๐๐ญ๐๐ฆ๐๐ง๐ญ๐ฌ:
Want to categorize or bucket data without creating a separate table? Use CASE. Itโs ideal for conditional logic, custom labels, and grouping in a single query.
7. ๐๐ ๐ ๐ซ๐๐ ๐๐ญ๐ข๐จ๐ง๐ฌ & ๐๐๐๐๐ ๐๐
Most analytics questions start with "how many", "whatโs the average", or "which is the highest?". SUM(), COUNT(), AVG(), etc., and pair them with GROUP BY to drive insights that matter.
8. ๐๐๐ญ๐๐ฌ ๐๐ซ๐ ๐๐ฅ๐ฐ๐๐ฒ๐ฌ ๐๐ซ๐ข๐๐ค๐ฒ
Time-based analysis is everywhere: trends, cohorts, seasonality, etc. Get familiar with functions like DATEADD, DATEDIFF, DATE_TRUNC, and DATEPART to work confidently with time series data.
9. ๐๐๐ฅ๐-๐๐จ๐ข๐ง๐ฌ & ๐๐๐๐ฎ๐ซ๐ฌ๐ข๐ฏ๐ ๐๐ฎ๐๐ซ๐ข๐๐ฌ ๐๐จ๐ซ ๐๐ข๐๐ซ๐๐ซ๐๐ก๐ข๐๐ฌ
Whether it's org charts or product categories, not all data is flat. Learn how to join a table to itself or use recursive CTEs to navigate parent-child relationships effectively.
You donโt need to memorize 100 functions. You need to understand 10 really well and apply them smartly. These are the concepts I keep going back to not just in interviews, but in the real world where clarity, performance, and logic matter most.
1. ๐๐ซ๐๐๐ค ๐๐ญ ๐๐จ๐ฐ๐ง ๐ฐ๐ข๐ญ๐ก ๐๐๐๐ฌ (๐๐จ๐ฆ๐ฆ๐จ๐ง ๐๐๐๐ฅ๐ ๐๐ฑ๐ฉ๐ซ๐๐ฌ๐ฌ๐ข๐จ๐ง๐ฌ)
Ever worked on a query that became an unreadable monster? CTEs let you break that down into logical steps. You can treat them like temporary views โ great for simplifying logic and improving collaboration across your team.
2. ๐๐ฌ๐ ๐๐ข๐ง๐๐จ๐ฐ ๐ ๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐ฌ
Forget the mess of subqueries. With functions like ROW_NUMBER(), RANK(), LEAD() and LAG(), you can compare rows, rank items, or calculate running totals โ all within the same query. Total
3. ๐๐ฎ๐๐ช๐ฎ๐๐ซ๐ข๐๐ฌ (๐๐๐ฌ๐ญ๐๐ ๐๐ฎ๐๐ซ๐ข๐๐ฌ)
Yes, they're old school, but nested subqueries are still powerful. Use them when you want to filter based on results of another query or isolate logic step-by-step before joining with the big picture.
4. ๐๐ง๐๐๐ฑ๐๐ฌ & ๐๐ฎ๐๐ซ๐ฒ ๐๐ฉ๐ญ๐ข๐ฆ๐ข๐ณ๐๐ญ๐ข๐จ๐ง
Query taking forever? Look at your indexes. Index the columns you use in JOINs, WHERE, and GROUP BY. Even basic knowledge of how the SQL engine reads data can take your skills up a notch.
5. ๐๐จ๐ข๐ง๐ฌ ๐ฏ๐ฌ. ๐๐ฎ๐๐ช๐ฎ๐๐ซ๐ข๐๐ฌ
Joins are usually faster and better for combining large datasets. Subqueries, on the other hand, are cleaner when doing one-off filters or smaller operations. Choose wisely based on the context.
6. ๐๐๐๐ ๐๐ญ๐๐ญ๐๐ฆ๐๐ง๐ญ๐ฌ:
Want to categorize or bucket data without creating a separate table? Use CASE. Itโs ideal for conditional logic, custom labels, and grouping in a single query.
7. ๐๐ ๐ ๐ซ๐๐ ๐๐ญ๐ข๐จ๐ง๐ฌ & ๐๐๐๐๐ ๐๐
Most analytics questions start with "how many", "whatโs the average", or "which is the highest?". SUM(), COUNT(), AVG(), etc., and pair them with GROUP BY to drive insights that matter.
8. ๐๐๐ญ๐๐ฌ ๐๐ซ๐ ๐๐ฅ๐ฐ๐๐ฒ๐ฌ ๐๐ซ๐ข๐๐ค๐ฒ
Time-based analysis is everywhere: trends, cohorts, seasonality, etc. Get familiar with functions like DATEADD, DATEDIFF, DATE_TRUNC, and DATEPART to work confidently with time series data.
9. ๐๐๐ฅ๐-๐๐จ๐ข๐ง๐ฌ & ๐๐๐๐ฎ๐ซ๐ฌ๐ข๐ฏ๐ ๐๐ฎ๐๐ซ๐ข๐๐ฌ ๐๐จ๐ซ ๐๐ข๐๐ซ๐๐ซ๐๐ก๐ข๐๐ฌ
Whether it's org charts or product categories, not all data is flat. Learn how to join a table to itself or use recursive CTEs to navigate parent-child relationships effectively.
You donโt need to memorize 100 functions. You need to understand 10 really well and apply them smartly. These are the concepts I keep going back to not just in interviews, but in the real world where clarity, performance, and logic matter most.
โค2๐1
๐๐ง๐๐ (๐๐ผ๐บ๐บ๐ผ๐ป ๐ง๐ฎ๐ฏ๐น๐ฒ ๐๐
๐ฝ๐ฟ๐ฒ๐๐๐ถ๐ผ๐ป๐)
CTEs can make complex queries more readable and easier to maintain.
They are excellent for breaking down complex queries into simpler, more manageable parts.
CTEs are most efficient for organizing query logic but don't inherently improve performance.
Since CTEs do not store their results. They act as temporary views executed every time they are referenced.
๐ง๐ฒ๐บ๐ฝ๐ผ๐ฟ๐ฎ๐ฟ๐ ๐ง๐ฎ๐ฏ๐น๐ฒ๐
But we also have Temporary tables, and they come with Performance through Persistence.
Temporary tables store data in the database's temporary storage (e.g., the tempdb in SQL Server).
On Temporary tables, you can also define indexes!!!
This physical storage and the indexes will make the reads or joins X times faster.
๐ง๐;๐๐ฅ:
CTEs are excellent for organizing and simplifying complex SQL queries without storing intermediate results, making them easy to read and maintain.
Temporary Tables are better suited for performance optimization of large datasets, indexing, and reducing the need for repeated computations.
CTEs are used because of their readability, but the performance on Temporary Tables is hard to ignore for large datasets.
CTEs can make complex queries more readable and easier to maintain.
They are excellent for breaking down complex queries into simpler, more manageable parts.
CTEs are most efficient for organizing query logic but don't inherently improve performance.
Since CTEs do not store their results. They act as temporary views executed every time they are referenced.
๐ง๐ฒ๐บ๐ฝ๐ผ๐ฟ๐ฎ๐ฟ๐ ๐ง๐ฎ๐ฏ๐น๐ฒ๐
But we also have Temporary tables, and they come with Performance through Persistence.
Temporary tables store data in the database's temporary storage (e.g., the tempdb in SQL Server).
On Temporary tables, you can also define indexes!!!
This physical storage and the indexes will make the reads or joins X times faster.
๐ง๐;๐๐ฅ:
CTEs are excellent for organizing and simplifying complex SQL queries without storing intermediate results, making them easy to read and maintain.
Temporary Tables are better suited for performance optimization of large datasets, indexing, and reducing the need for repeated computations.
CTEs are used because of their readability, but the performance on Temporary Tables is hard to ignore for large datasets.
๐3
SQL Joins โ Essential Concepts ๐
1๏ธโฃ What Are SQL Joins?
SQL Joins are used to combine rows from two or more tables based on a related column.
2๏ธโฃ Types of Joins
INNER JOIN: Returns only matching rows from both tables.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id;
LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table and matching rows from the right table.
SELECT * FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id;
RIGHT JOIN (RIGHT OUTER JOIN): Returns all rows from the right table and matching rows from the left table.
SELECT * FROM TableA RIGHT JOIN TableB ON TableA.id = TableB.id;
FULL JOIN (FULL OUTER JOIN): Returns all rows when there is a match in either table.
SELECT * FROM TableA FULL JOIN TableB ON TableA.id = TableB.id;
3๏ธโฃ Self Join
A table joins with itself to compare rows.
SELECT A.name, B.name FROM Employees A JOIN Employees B ON A.manager_id = B.id;
4๏ธโฃ Cross Join
Returns the Cartesian product of both tables (every row from Table A pairs with every row from Table B).
SELECT * FROM TableA CROSS JOIN TableB;
5๏ธโฃ Joins with Multiple Conditions
Using multiple columns for matching.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id AND TableA.type = TableB.type;
6๏ธโฃ Using Aliases in Joins
Shortens table names for better readability.
SELECT A.name, B.salary FROM Employees A INNER JOIN Salaries B ON A.id = B.emp_id;
7๏ธโฃ Handling NULLs in Joins
Use COALESCE(column, default_value) to replace NULL values.
IS NULL to filter unmatched rows in LEFT or RIGHT JOINs.
Free SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
React with โค๏ธ for free resources
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
1๏ธโฃ What Are SQL Joins?
SQL Joins are used to combine rows from two or more tables based on a related column.
2๏ธโฃ Types of Joins
INNER JOIN: Returns only matching rows from both tables.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id;
LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table and matching rows from the right table.
SELECT * FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id;
RIGHT JOIN (RIGHT OUTER JOIN): Returns all rows from the right table and matching rows from the left table.
SELECT * FROM TableA RIGHT JOIN TableB ON TableA.id = TableB.id;
FULL JOIN (FULL OUTER JOIN): Returns all rows when there is a match in either table.
SELECT * FROM TableA FULL JOIN TableB ON TableA.id = TableB.id;
3๏ธโฃ Self Join
A table joins with itself to compare rows.
SELECT A.name, B.name FROM Employees A JOIN Employees B ON A.manager_id = B.id;
4๏ธโฃ Cross Join
Returns the Cartesian product of both tables (every row from Table A pairs with every row from Table B).
SELECT * FROM TableA CROSS JOIN TableB;
5๏ธโฃ Joins with Multiple Conditions
Using multiple columns for matching.
SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id AND TableA.type = TableB.type;
6๏ธโฃ Using Aliases in Joins
Shortens table names for better readability.
SELECT A.name, B.salary FROM Employees A INNER JOIN Salaries B ON A.id = B.emp_id;
7๏ธโฃ Handling NULLs in Joins
Use COALESCE(column, default_value) to replace NULL values.
IS NULL to filter unmatched rows in LEFT or RIGHT JOINs.
Free SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
React with โค๏ธ for free resources
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
๐4๐1
1. What are the different subsets of SQL?
Data Definition Language (DDL) โ It allows you to perform various operations on the database such as CREATE, ALTER, and DELETE objects.
Data Manipulation Language(DML) โ It allows you to access and manipulate data. It helps you to insert, update, delete and retrieve data from the database.
Data Control Language(DCL) โ It allows you to control access to the database. Example โ Grant, Revoke access permissions.
2. List the different types of relationships in SQL.
There are different types of relations in the database:
One-to-One โ This is a connection between two tables in which each record in one table corresponds to the maximum of one record in the other.
One-to-Many and Many-to-One โ This is the most frequent connection, in which a record in one table is linked to several records in another.
Many-to-Many โ This is used when defining a relationship that requires several instances on each sides.
Self-Referencing Relationships โ When a table has to declare a connection with itself, this is the method to employ.
3. What is a Stored Procedure?
A stored procedure is a subroutine available to applications that access a relational database management system (RDBMS). Such procedures are stored in the database data dictionary. The sole disadvantage of stored procedure is that it can be executed nowhere except in the database and occupies more memory in the database server.
4. What is Pattern Matching in SQL?
SQL pattern matching provides for pattern search in data if you have no clue as to what that word should be. This kind of SQL query uses wildcards to match a string pattern, rather than writing the exact word. The LIKE operator is used in conjunction with SQL Wildcards to fetch the required information.
Data Definition Language (DDL) โ It allows you to perform various operations on the database such as CREATE, ALTER, and DELETE objects.
Data Manipulation Language(DML) โ It allows you to access and manipulate data. It helps you to insert, update, delete and retrieve data from the database.
Data Control Language(DCL) โ It allows you to control access to the database. Example โ Grant, Revoke access permissions.
2. List the different types of relationships in SQL.
There are different types of relations in the database:
One-to-One โ This is a connection between two tables in which each record in one table corresponds to the maximum of one record in the other.
One-to-Many and Many-to-One โ This is the most frequent connection, in which a record in one table is linked to several records in another.
Many-to-Many โ This is used when defining a relationship that requires several instances on each sides.
Self-Referencing Relationships โ When a table has to declare a connection with itself, this is the method to employ.
3. What is a Stored Procedure?
A stored procedure is a subroutine available to applications that access a relational database management system (RDBMS). Such procedures are stored in the database data dictionary. The sole disadvantage of stored procedure is that it can be executed nowhere except in the database and occupies more memory in the database server.
4. What is Pattern Matching in SQL?
SQL pattern matching provides for pattern search in data if you have no clue as to what that word should be. This kind of SQL query uses wildcards to match a string pattern, rather than writing the exact word. The LIKE operator is used in conjunction with SQL Wildcards to fetch the required information.
โค2๐1๐1
10 SQL Concepts Every Data Analyst Should Master ๐
โ SELECT, WHERE, ORDER BY โ Core of querying your data
โ JOINs (INNER, LEFT, RIGHT, FULL) โ Combine data from multiple tables
โ GROUP BY & HAVING โ Aggregate and filter grouped data
โ Subqueries โ Nest queries inside queries for complex logic
โ CTEs (Common Table Expressions) โ Write cleaner, reusable SQL logic
โ Window Functions โ Perform advanced analytics like rankings & running totals
โ Indexes โ Boost your query performance
โ Normalization โ Structure your database efficiently
โ UNION vs UNION ALL โ Combine result sets with or without duplicates
โ Stored Procedures & Functions โ Reusable logic inside your DB
React with โค๏ธ if you want me to cover each topic in detail
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
โ SELECT, WHERE, ORDER BY โ Core of querying your data
โ JOINs (INNER, LEFT, RIGHT, FULL) โ Combine data from multiple tables
โ GROUP BY & HAVING โ Aggregate and filter grouped data
โ Subqueries โ Nest queries inside queries for complex logic
โ CTEs (Common Table Expressions) โ Write cleaner, reusable SQL logic
โ Window Functions โ Perform advanced analytics like rankings & running totals
โ Indexes โ Boost your query performance
โ Normalization โ Structure your database efficiently
โ UNION vs UNION ALL โ Combine result sets with or without duplicates
โ Stored Procedures & Functions โ Reusable logic inside your DB
React with โค๏ธ if you want me to cover each topic in detail
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
๐5โค3
SQL Basics for Data Analysts
SQL (Structured Query Language) is used to retrieve, manipulate, and analyze data stored in databases.
1๏ธโฃ Understanding Databases & Tables
Databases store structured data in tables.
Tables contain rows (records) and columns (fields).
Each column has a specific data type (INTEGER, VARCHAR, DATE, etc.).
2๏ธโฃ Basic SQL Commands
Let's start with some fundamental queries:
๐น SELECT โ Retrieve Data
๐น WHERE โ Filter Data
๐น ORDER BY โ Sort Data
๐น LIMIT โ Restrict Number of Results
๐น DISTINCT โ Remove Duplicates
Mini Task for You: Try to write an SQL query to fetch the top 3 highest-paid employees from an "employees" table.
You can find free SQL Resources here
๐๐
https://t.iss.one/mysqldata
Like this post if you want me to continue covering all the topics! ๐โค๏ธ
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
#sql
SQL (Structured Query Language) is used to retrieve, manipulate, and analyze data stored in databases.
1๏ธโฃ Understanding Databases & Tables
Databases store structured data in tables.
Tables contain rows (records) and columns (fields).
Each column has a specific data type (INTEGER, VARCHAR, DATE, etc.).
2๏ธโฃ Basic SQL Commands
Let's start with some fundamental queries:
๐น SELECT โ Retrieve Data
SELECT * FROM employees; -- Fetch all columns from 'employees' table SELECT name, salary FROM employees; -- Fetch specific columns
๐น WHERE โ Filter Data
SELECT * FROM employees WHERE department = 'Sales'; -- Filter by department SELECT * FROM employees WHERE salary > 50000; -- Filter by salary
๐น ORDER BY โ Sort Data
SELECT * FROM employees ORDER BY salary DESC; -- Sort by salary (highest first) SELECT name, hire_date FROM employees ORDER BY hire_date ASC; -- Sort by hire date (oldest first)
๐น LIMIT โ Restrict Number of Results
SELECT * FROM employees LIMIT 5; -- Fetch only 5 rows SELECT * FROM employees WHERE department = 'HR' LIMIT 10; -- Fetch first 10 HR employees
๐น DISTINCT โ Remove Duplicates
SELECT DISTINCT department FROM employees; -- Show unique departments
Mini Task for You: Try to write an SQL query to fetch the top 3 highest-paid employees from an "employees" table.
You can find free SQL Resources here
๐๐
https://t.iss.one/mysqldata
Like this post if you want me to continue covering all the topics! ๐โค๏ธ
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
#sql
๐4๐1
1. How to change a table name in SQL?
This is the command to change a table name in SQL:
ALTER TABLE table_name
RENAME TO new_table_name;
We will start off by giving the keywords ALTER TABLE, then we will follow it up by giving the original name of the table, after that, we will give in the keywords RENAME TO and finally, we will give the new table name.
2. Find the Constraint information from the table?
There are so many times where user needs to find out the specific constraint information of the table. The following queries are useful, SELECT * From User_Constraints; SELECT * FROM User_Cons_Columns;
3. What is the difference between clustered and non-clustered indexes?
Clustered indexes can be read rapidly rather than non-clustered indexes.
Clustered indexes store data physically in the table or view whereas, non-clustered indexes do not store data in the table as it has separate structure from the data row.
4. What are the subsets of SQL?
DDL (Data Definition Language): Used to define the data structure it consists of the commands like CREATE, ALTER, DROP, etc.
DML (Data Manipulation Language): Used to manipulate already existing data in the database, commands like SELECT, UPDATE, INSERT
DCL (Data Control Language): Used to control access to data in the database, commands like GRANT, REVOKE.
This is the command to change a table name in SQL:
ALTER TABLE table_name
RENAME TO new_table_name;
We will start off by giving the keywords ALTER TABLE, then we will follow it up by giving the original name of the table, after that, we will give in the keywords RENAME TO and finally, we will give the new table name.
2. Find the Constraint information from the table?
There are so many times where user needs to find out the specific constraint information of the table. The following queries are useful, SELECT * From User_Constraints; SELECT * FROM User_Cons_Columns;
3. What is the difference between clustered and non-clustered indexes?
Clustered indexes can be read rapidly rather than non-clustered indexes.
Clustered indexes store data physically in the table or view whereas, non-clustered indexes do not store data in the table as it has separate structure from the data row.
4. What are the subsets of SQL?
DDL (Data Definition Language): Used to define the data structure it consists of the commands like CREATE, ALTER, DROP, etc.
DML (Data Manipulation Language): Used to manipulate already existing data in the database, commands like SELECT, UPDATE, INSERT
DCL (Data Control Language): Used to control access to data in the database, commands like GRANT, REVOKE.
๐5โค2๐2
Here are some essential SQL tips for beginners ๐๐
โ Primary Key = Unique Key + Not Null constraint
โ To perform case insensitive search use UPPER() function ex. UPPER(customer_name) LIKE โA%Aโ
โ LIKE operator is for string data type
โ COUNT(*), COUNT(1), COUNT(0) all are same
โ All aggregate functions ignore the NULL values
โ Aggregate functions MIN, MAX, SUM, AVG, COUNT are for int data type whereas STRING_AGG is for string data type
โ For row level filtration use WHERE and aggregate level filtration use HAVING
โ UNION ALL will include duplicates where as UNION excludes duplicates
โ If the results will not have any duplicates, use UNION ALL instead of UNION
โ We have to alias the subquery if we are using the columns in the outer select query
โ Subqueries can be used as output with NOT IN condition.
โ CTEs look better than subqueries. Performance wise both are same.
โ When joining two tables , if one table has only one value then we can use 1=1 as a condition to join the tables. This will be considered as CROSS JOIN.
โ Window functions work at ROW level.
โ The difference between RANK() and DENSE_RANK() is that RANK() skips the rank if the values are the same.
โ EXISTS works on true/false conditions. If the query returns at least one value, the condition is TRUE. All the records corresponding to the conditions are returned.
Like for more ๐๐
โ Primary Key = Unique Key + Not Null constraint
โ To perform case insensitive search use UPPER() function ex. UPPER(customer_name) LIKE โA%Aโ
โ LIKE operator is for string data type
โ COUNT(*), COUNT(1), COUNT(0) all are same
โ All aggregate functions ignore the NULL values
โ Aggregate functions MIN, MAX, SUM, AVG, COUNT are for int data type whereas STRING_AGG is for string data type
โ For row level filtration use WHERE and aggregate level filtration use HAVING
โ UNION ALL will include duplicates where as UNION excludes duplicates
โ If the results will not have any duplicates, use UNION ALL instead of UNION
โ We have to alias the subquery if we are using the columns in the outer select query
โ Subqueries can be used as output with NOT IN condition.
โ CTEs look better than subqueries. Performance wise both are same.
โ When joining two tables , if one table has only one value then we can use 1=1 as a condition to join the tables. This will be considered as CROSS JOIN.
โ Window functions work at ROW level.
โ The difference between RANK() and DENSE_RANK() is that RANK() skips the rank if the values are the same.
โ EXISTS works on true/false conditions. If the query returns at least one value, the condition is TRUE. All the records corresponding to the conditions are returned.
Like for more ๐๐
๐6โค3๐1