\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{sourabhsahu12345} \pdfinfo{ /Title (sql-cheatsheet-for-data-analytics.pdf) /Creator (Cheatography) /Author (sourabhsahu12345) /Subject (SQL Cheatsheet for Data Analytics Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A35B14} \definecolor{LightBackground}{HTML}{F9F4F0} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{SQL Cheatsheet for Data Analytics Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{sourabhsahu12345} via \textcolor{DarkBackground}{\uline{cheatography.com/192985/cs/40126/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}sourabhsahu12345 \\ \uline{cheatography.com/sourabhsahu12345} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 3rd September, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{3.23505 cm} x{1.74195 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{RDBMS Softwares}} \tn % Row 0 \SetRowColor{LightBackground} Oracle & MYSQL \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} MS SQL Server & MariaDB \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Follow @Sourabh Sahu}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{QUERYING DATA}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Fetch all columns from the products table: SELECT * FROM products;} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Fetch product IDs and names from the inventory table: SELECT product\_id, product\_name FROM inventory;} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Fetch employee names sorted by their salary in descending order: SELECT employee\_name FROM employees ORDER BY salary DESC;} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Fetch customer names sorted by their registration date in ascending order (default): SELECT customer\_name FROM customers ORDER BY registration\_date;} \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ALIASING (AS)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{SELECT name AS product\_name FROM products;} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{INDEXING}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Indexing improves data retrieval speed by creating a reference system. It enhances query performance but may slightly impact insert/update operations.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Clustered Index: Dictates physical data order, often used for primary keys. Non-Clustered Index: Creates separate index structures, allowing multiple indexes for specific columns, without affecting data storage order.} \tn % Row Count 8 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{BETWEEN AND IN}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{IN checks if a column value matches any value in a list, while BETWEEN checks if a column value falls within a specified range.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT * FROM product WHERE category IN ('Electronics', 'Clothing', 'Furniture');} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{SELECT * FROM product WHERE price BETWEEN 20 AND 50;} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{CONSTRAINTS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Constraints are rules applied to database tables to ensure data accuracy, integrity, and consistency.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{PRIMARY KEY enforces unique, non-null values in the "product\_id" column.} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{FOREIGN KEY links the "manufacturer\_id" column to a related table.} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{NOT NULL ensures the "product\_name" must have a value.} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{CHECK enforces a condition, like ensuring "price" is positive.} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{DEFAULT assigns a default value to a column when no value is provided during insertion.} \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{CREATE TABLE product ( product\_id INT PRIMARY KEY, product\_name VARCHAR(255) NOT NULL, price DECIMAL(10, 2) CHECK (price \textgreater{} 0), manufacturer\_id INT, FOREIGN KEY (manufacturer\_id) REFERENCES \seqsplit{manufacturer(manufacturer\_id)}, discount DECIMAL(5, 2) DEFAULT 0.00 -{}- Default discount set to 0.00 );} \tn % Row Count 20 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{SUBQUERIES}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Scalar Subquery: Returns a single value and can be used within SELECT, WHERE, or FROM clauses.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_name, (SELECT MAX(price) FROM products) AS max\_price FROM products;} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Single-Row Subquery: Subquery that returns a single row of results, typically used in comparison operations.} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_name FROM products WHERE price = (SELECT MAX(price) FROM products);} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Multi-Row Subquery: Subquery that returns multiple rows, often used with IN, ANY, or ALL operators.} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_name FROM products WHERE manufacturer\_id IN (SELECT manufacturer\_id FROM manufacturers WHERE country = 'USA');} \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Correlated Subquery: References values from the outer query within the subquery.} \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_name FROM products p WHERE price \textgreater{} (SELECT AVG(price) FROM products WHERE manufacturer\_id = p.manufacturer\_id);} \tn % Row Count 19 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Inline View Subquery: Creates a temporary table-like structure for complex subqueries within the FROM clause.} \tn % Row Count 22 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT AVG(subquery.avg\_price) FROM (SELECT manufacturer\_id, AVG(price) AS avg\_price FROM products GROUP BY manufacturer\_id) AS subquery;} \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{SQL and NO SQL}} \tn % Row 0 \SetRowColor{LightBackground} Uses a structured, tabular data model with predefined schemas. & Offers various flexible data models, suitable for semi-structured or unstructured data. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} Primarily designed for vertical scaling, can be complex to scale horizontally & Designed for horizontal scalability, making it easier to handle high traffic and large datasets. \tn % Row Count 10 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{WINDOW AND RANKING FUNCTIONS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Window functions allow you to perform calculations across a set of rows related to the current row within the result set. Rank functions assign a rank or row number to each row based on specified criteria.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_name, price, ROW\_NUMBER() OVER (ORDER BY price) AS row\_num, DENSE\_RANK() OVER (ORDER BY price) AS dense\_rank, SUM(price) OVER (PARTITION BY manufacturer\_id) AS manufacturer\_total FROM products;} \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{we use window functions like ROW\_NUMBER, DENSE\_RANK, and SUM with the "products" table to assign row numbers, dense ranks, and calculate the total price for each manufacturer's products.} \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{RANK assigns the same rank to rows with equal values, leaving gaps, while DENSE\_RANK assigns consecutive ranks without gaps, and ROW\_NUMBER assigns a unique row number to each row.} \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{SET OPERATION}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{INTERSECT: Returns the common rows between two SELECT statements. Retrieves products that exist in both sets of results.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_id, product\_name FROM products INTERSECT SELECT product\_id, product\_name FROM some\_other\_table;} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{UNION: Combines the results of two SELECT statements, removing duplicates. Retrieves all unique products from both sets of results.} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_id, product\_name FROM products UNION SELECT product\_id, product\_name FROM some\_other\_table;} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{UNION ALL: Similar to UNION, but includes all rows, including duplicates. Retrieves all products from both sets of results, allowing duplicates.} \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_id, product\_name FROM products UNION ALL SELECT product\_id, product\_name FROM some\_other\_table;} \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{EXCEPT: Returns rows that exist in the first SELECT statement but not in the second. Retrieves products that are in the "products" table but not in "some\_other\_table."} \tn % Row Count 22 (+ 4) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT product\_id, product\_name FROM products EXCEPT SELECT product\_id, product\_name FROM some\_other\_table;} \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{IS NULL / IS NOT NULL}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{IS NULL: Filters rows where the "manufacturer\_id" is not assigned. SELECT * FROM product WHERE manufacturer\_id IS NULL;} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{IS NOT NULL: Filters rows where the "manufacturer\_id" is assigned. SELECT * FROM product WHERE manufacturer\_id IS NOT NULL;} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{FILTERING}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Retrieve all products with a price greater than \$50: SELECT * FROM product WHERE price \textgreater{} 50;} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Get products with a quantity in stock less than or equal to 10: SELECT * FROM product WHERE stock\_quantity \textless{}= 10;} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Retrieve products with a specific category (e.g., "Electronics"): SELECT * FROM product WHERE category = 'Electronics';} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Find products with names containing the word "phone": SELECT * FROM product WHERE product\_name LIKE '\%phone\%';} \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Get products added after a certain date (e.g., '2023-01-01'): SELECT * FROM product WHERE date\_added \textgreater{} '2023-01-01';} \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Retrieve products with a price between \$20 and \$30: SELECT * FROM product WHERE price BETWEEN 20 AND 30;} \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Find products with low stock and a price greater than \$50: SELECT * FROM product WHERE stock\_quantity \textless{} 5 AND price \textgreater{} 50;} \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Retrieve products from a specific manufacturer (e.g., "Samsung"): SELECT * FROM product WHERE manufacturer = 'Samsung';} \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{JOINS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{INNER JOIN: Returns only the rows with matching values in both tables.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT * FROM sales INNER JOIN products ON sales.product\_id = products.product\_id;} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{LEFT JOIN (or LEFT OUTER JOIN): Returns all sales records and their corresponding products. If a product has no sales, it still appears with NULL values in sales-related columns.} \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT * FROM products LEFT JOIN sales ON products.product\_id = sales.product\_id;} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{RIGHT JOIN (or RIGHT OUTER JOIN): Opposite of the LEFT JOIN. Returns all sales records and includes products that have no sales} \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT * FROM sales RIGHT JOIN products ON sales.product\_id = products.product\_id;} \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{FULL OUTER JOIN: Returns all sales records and all products, including those without sales. NULL values appear where there is no match.} \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT * FROM products FULL OUTER JOIN sales ON products.product\_id = sales.product\_id;} \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{SELF JOIN: A self join could be used if the "sales" table contains information about salespeople who sell products. You might join the table with itself to identify salespeople who have sold the same products.} \tn % Row Count 25 (+ 5) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT s1.salesperson\_name, s2.salesperson\_name FROM sales AS s1 JOIN sales AS s2 ON s1.product\_id = s2.product\_id WHERE s1.salesperson\_name \textless{}\textgreater{} s2.salesperson\_name;} \tn % Row Count 29 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{AGGREGATION AND GROUPING}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Aggregation functions like COUNT, SUM, AVG, MAX, and MIN are used to perform calculations on data. GROUP BY clause is used to group rows based on one or more columns. Aggregation functions are applied to each group, providing summary information.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{-{}- Count the total number of products SELECT COUNT(*) AS total\_products FROM products;} \tn % Row Count 7 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{-{}- Calculate the total price of all products SELECT SUM(price) AS total\_price FROM products;} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{-{}- Calculate the average price of products SELECT AVG(price) AS average\_price FROM products;} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{-{}- Find the highest product price SELECT MAX(price) AS highest\_price FROM products;} \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{-{}- Find the lowest product price SELECT MIN(price) AS lowest\_price FROM products;} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{DIMENSIONAL MODELLING}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A design approach for data warehousing.} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Organizes data into fact tables (quantitative data) and dimension tables (descriptive data).} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Simplifies complex queries, improves performance, and supports business analytics by creating a logical structure for data analysis.} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{PERFORMANCE OPTIMIZATION}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Indexing: Use appropriate indexes.} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Optimize Queries: Write efficient SQL.} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Limit Data Retrieval: Fetch only needed data.} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Normalization: Properly structure tables.} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Stored Procedures: Use precompiled procedures.} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Table Partitioning: Divide large tables.} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Regular Maintenance: Rebuild indexes, update stats.} \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Optimize Hardware: Ensure server resources.} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Caching: Implement caching mechanisms.} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Use Proper Data Types: Choose suitable types.} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Concurrency Control: Manage transactions carefully.} \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.55618 cm} x{1.51041 cm} x{1.51041 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} CHAR(N): Fixed-length character string with a specified maximum length of N. & VARCHAR(N): \seqsplit{Variable-length} character string with a maximum length of N. & VARCHAR and VARCHAR2 are used \seqsplit{interchangeably} in most databases, but VARCHAR2 is specific to Oracle databases. \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} INTEGER,FLOAT,BOOLEAN & BLOB: Stores binary large objects, such as images or files. & DATETIME: Combines date and time in 'YYYY-MM-DD HH:MM:SS' format. \tn % Row Count 14 (+ 5) % Row 2 \SetRowColor{LightBackground} DECIMAL(P, S): Fixed-point decimal number with P total digits and S decimal places. & DATE: Stores a date value in the format \seqsplit{'YYYY-MM-DD'.} & TIME: Represents a time of day in 'HH:MM:SS' format. \tn % Row Count 21 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}