\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{Remidy08} \pdfinfo{ /Title (sql.pdf) /Creator (Cheatography) /Author (Remidy08) /Subject (SQL 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}{A30B0B} \definecolor{LightBackground}{HTML}{FCF7F7} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Remidy08} via \textcolor{DarkBackground}{\uline{cheatography.com/159206/cs/33576/}}} \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}Remidy08 \\ \uline{cheatography.com/remidy08} \\ \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 12th September, 2022.\\ 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{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Understanding SQL}} \tn % Row 0 \SetRowColor{LightBackground} Database: & container to store organized data \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Database Management System (DBMS): & manipulates the database \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Table: & structured list of data of a specific type. There cannot be repeated names for tables in the same database \tn % Row Count 10 (+ 6) % Row 3 \SetRowColor{white} Schema: & Information about database and table layout and properties \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} Datatype: & A type of allowed dat in a certain column \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} Primary Keys: & A column whose values uniquely identify every row in a table. They are not mandatory but most people that create a database use them. These should never be updated or reused \tn % Row Count 24 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Filtering Data}} \tn % Row 0 \SetRowColor{LightBackground} WHERE & specified right after the table name (before ORDER BY. It is used to filter the data \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{Operators} & used in the WHERE clause. They can be: = (equality); \textless{}\textgreater{} or != (nonequality), \textless{} (less than), \textless{}= (less than or equal), !\textless{} (not less than), \textgreater{} (greater than), \textgreater{}= (greater or equal than), !\textgreater{} (not greater than), BETWEEN, IS NULL \tn % Row Count 10 (+ 7) % Row 2 \SetRowColor{LightBackground} AND & used to append conditions to the WHERE clause. \tn % Row Count 12 (+ 2) % Row 3 \SetRowColor{white} OR & instructs the database management system to retrieve rows that match either condition. \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} IN & used to specify a range of conditions, any of which can be matched. It takes a comma-delimited list of valid values, all enclosed within parentheses. \tn % Row Count 20 (+ 5) % Row 5 \SetRowColor{white} NOT & can be used before the column to filter on, not just after it. Negates whatever condition comes next to it. \tn % Row Count 24 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{We can do the same with the IN and OR operators, but the IN has the advantage of being easier to read; is easier to use in conjuction with other AND and OR operators; In often executes more quickly; it allows to build subqueries.} \tn \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}{Data Manipulation Functions}} \tn % Row 0 \SetRowColor{LightBackground} SUBSTR() (DB2, Oracle, PostgreSQL, and SQLITE) or SUBSTRING() (MariaDB, MySQL and SQL Server) & Extract part of a string \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} CAST() (DB2, PostgreSQL, SQL Server) or CONVERT() (MariaDB, MySQL, and SQL Server {[}appears in both{]}) & Data type conversion. Oracle has multiple functions, one for each type \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} CURRET\_DATE (DB2 and PostgreSQL) or CURDATE() (MariaDB and MySQL) or SYSDATE (Oracle) or GETDATE() (SQL Server) or DATE() (SQLite) & Get current date \tn % Row Count 17 (+ 7) % Row 3 \SetRowColor{white} UPPER() & converts text to uppercase \tn % Row Count 19 (+ 2) % Row 4 \SetRowColor{LightBackground} LEFT() & returns characters from the left of a string \tn % Row Count 22 (+ 3) % Row 5 \SetRowColor{white} LENGTH() or DATALENGTH() or LEN() & returns the length of a string \tn % Row Count 24 (+ 2) % Row 6 \SetRowColor{LightBackground} LOWER() & converts a string to lower case \tn % Row Count 26 (+ 2) % Row 7 \SetRowColor{white} RIGHT() & returns characters from the right of a string \tn % Row Count 29 (+ 3) % Row 8 \SetRowColor{LightBackground} SOUNDEX() (PostgreSQL) & returns a string's SOUNDEX value, like the name says, it returns strings with simmilar sounds \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Manipulation Functions (cont)}} \tn % Row 9 \SetRowColor{LightBackground} DATEPART(yy, column)) (SQL Server) or DATE\_PART('year', column) (PostgreSQL)) & returns the part of the date that we want to use \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} EXTRACT(year FROM column) & extracts part of the date with year specifying what part of the date to extract \tn % Row Count 8 (+ 4) % Row 11 \SetRowColor{LightBackground} to\_date(date, 'yyyy-mm-dd') & converts strings into dates. It can be used in a BETWEEN statement \tn % Row Count 12 (+ 4) % Row 12 \SetRowColor{white} YEAR() (DB2, MySQL, and MariaDB) & extracts the year from date. \tn % Row Count 14 (+ 2) % Row 13 \SetRowColor{LightBackground} MONTH() (DB2, MySQL, and MariaDB) & extracts the month from date. \tn % Row Count 16 (+ 2) % Row 14 \SetRowColor{white} DAY() (DB2, MySQL, and MariaDB) & extracts the day from date. \tn % Row Count 18 (+ 2) % Row 15 \SetRowColor{LightBackground} strftime('\%Y', column) & extracts part of a date. \tn % Row Count 20 (+ 2) % Row 16 \SetRowColor{white} ABS() & returns a number's absolute value \tn % Row Count 22 (+ 2) % Row 17 \SetRowColor{LightBackground} COS() & returns the trignometric cosine of a specific angle \tn % Row Count 25 (+ 3) % Row 18 \SetRowColor{white} EXP() & returns the trignometric exponential value of a specific number \tn % Row Count 29 (+ 4) % Row 19 \SetRowColor{LightBackground} PI() & returns the value of pi \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Manipulation Functions (cont)}} \tn % Row 20 \SetRowColor{LightBackground} SIN() & returns the trignometric sine of a specific angle \tn % Row Count 3 (+ 3) % Row 21 \SetRowColor{white} SQRT() & returns the trignometric root of a specific number \tn % Row Count 6 (+ 3) % Row 22 \SetRowColor{LightBackground} TAN() & returns the trignometric tangent of a specific angle \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{SQL functions are not portable, which means they vary between DBMS. \newline Write comments near functions.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Data sets}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{UC Irvine Machine Learning Repository} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Kaggle datasets} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Amazon's AWS datasets} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{http://dataportals.org/} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{http://opendatamonitor.eu/}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{http://quandl.com/} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Wikipedia's list of Machine Learning datasets} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Quora.com question} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Datasets subreddit} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Retrieving Data}} \tn % Row 0 \SetRowColor{LightBackground} SELECT & retrieves a specified set of elements (case insensitive). A different number of columns can be called, we just have to write them and separate with ','. If we want all columns we just need to specify '*' \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} FROM & refers the table we are retrieving the data from \tn % Row Count 11 (+ 2) % Row 2 \SetRowColor{LightBackground} ; & used to separate statements \tn % Row Count 13 (+ 2) % Row 3 \SetRowColor{white} DISTINCT & added just before the column name (it applies to all columns combinations of unique values). It is used when we want a value to appear only once in the output \tn % Row Count 20 (+ 7) % Row 4 \SetRowColor{LightBackground} TOP & Used in Microsoft SQL server to pass how many items, counting from the top, we want to show. Example: SELECT TOP n column FROM table \tn % Row Count 26 (+ 6) % Row 5 \SetRowColor{white} FETCH FIRST n ROWS ONLT & Used in DB2 to pass how many items, counting from the top, we want to show. It is placed after the table \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Retrieving Data (cont)}} \tn % Row 6 \SetRowColor{LightBackground} ROWNUM & Used in Oracle to pass how many items, counting from the top, we want to show. It is placed as if it was a WHERE statement. Example: WHERE ROWNUM \textless{}=5 \tn % Row Count 6 (+ 6) % Row 7 \SetRowColor{white} LIMIT & Used in MySQL, MariaDB, PostgreSQL, and SQLite to pass how many items, counting from the top, we want to show. Placed after the table argument with a number next to it. \tn % Row Count 13 (+ 7) % Row 8 \SetRowColor{LightBackground} OFFSET & If we use LIMIT, after we pass it, we can write this argument o specify that we want the next n rows after the previously specified ones. Instead of this, we can use LIMIT m,n, where n referes to the first rows and m to the OFFSET argument \tn % Row Count 23 (+ 10) % Row 9 \SetRowColor{white} Coments & To create a comment we either use '-{}-', '\#', or /{\emph{ (...) }}/, this last one is used for multiline comments. \tn % Row Count 28 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{The first row in a table is row 0 not 1.} \tn \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}{Creating Calculated Fields}} \tn % Row 0 \SetRowColor{LightBackground} + (SQL Server) or || (DB2, Oracle, PostgreSQL, SQLite) or CONCAT() (MySQL, MariaDB) & Used to concatenate/join columns. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} RTRIM() & removes white spaces on the right of a column. \tn % Row Count 8 (+ 3) % Row 2 \SetRowColor{LightBackground} LTRIM() & removes white spaces on the left of a column. \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} TRIM() & removes white spaces on the right and left of a column. \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} Alias & alternate name for a field value. To do this, we need to place an AS after the calculated field with the pretended name after it. If the alias has more than one word in it, its name should be inclose in quotes (this practice is discoraged) \tn % Row Count 26 (+ 12) % Row 5 \SetRowColor{white} Curdate() & returns the current date (MySQL and MariaDB) \tn % Row Count 29 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Calculated fields can include the sum or mutiplication of two columns, such as, column1 * column2.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.84609 cm} x{4.13091 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Grouping Data}} \tn % Row 0 \SetRowColor{LightBackground} GROUP BY & instructs the DBMS to sort the data and group by a certain column. More than when columns can be usesd in this clause. Instead of passing the columns name, we can pass their position \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \seqsplit{HAVING} & filters which groups to include. All the techniques learned with WHERE applies to HAVING as well. \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Every expression specified in the select has to be specified in the GROUP BY. \newline Most SQL implementations do not allow GROUP BY columns with variable length. \newline NULL can be returned as a group. \newline The GROUP BY comes before OERDER BY and after WHERE clauses. \newline Aliases cannot be used.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Working with Subqueries}} \tn % Row 0 \SetRowColor{LightBackground} Query & Any SQL statement, but the term is used to refer to a SELECT statement. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Fully Qualified column names & When we precede the name of a column with the name of the table followed by a '.'. Ex.: table.column \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} Subquery & This name is normally atributed to a SELECT statement within another SELECT statement. This is most commonly done in a WHERE clause \tn % Row Count 15 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Subquery SELECT statements can only retrieve a single column.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Joining Tables}} \tn % Row 0 \SetRowColor{LightBackground} SELECT ... FROM column1, column 2 & the number of rows retrieved will be the product of the number of rows in each table Cartesian product or cross join). \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} WHERE & in this case the condition passed into this clause should be the column we want to match in both tables. \tn % Row Count 11 (+ 5) % Row 2 \SetRowColor{LightBackground} INNER JOIN ... ON & used to join tables. We put the columns we want to join, one on each side of the INNER JOIN, with the condition after the ON. \tn % Row Count 17 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{The limit of the maximum number of tables in a join should be accessed in the DBMS documentation.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Sorting Retrieved Data}} \tn % Row 0 \SetRowColor{LightBackground} Clause & usually consists of a keyword and suplied data \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} ORDER BY & Be sure it is the last clause in the SELECT statement with a column in front of it to mention in which order we should organize the table. It is not mandatory to select the column by which we order the table. Instead of using a column name, we could use its position \tn % Row Count 12 (+ 10) % Row 2 \SetRowColor{LightBackground} DESC or DESCENDING & Added after the column in order by to make the order descending, instead of ascending. The DESC only applies to the column that preceedes it \tn % Row Count 18 (+ 6) % Row 3 \SetRowColor{white} ASC or ASCEDING & It is the default value of the ORDER BY, does the opposite of the previous one \tn % Row Count 21 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{ORDER BY is case insenstive, so letters like A and a, come in the same order. In some case, if there are foreign characters in the data set, it may be necessary for the data base administrator to change this behavior. By doing this, it is impossible to organize the data like you want, with a simple ORDER BY.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Using Wildcard Filtering}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Wildcards} & S pecial character used to match parts of a value \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} LIKE & to use wildcards in search clauses, you must use this operator. To use place it after a column refered in a WHERE cluase with a search pattern in front of it. \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{Predicate} & expression that evaluates to TRUE, FALSE, or UNKNOWN. Predicates are used in the search condition of WHERE clauses and HAVING clauses, the join conditions of FROM clauses, and other constructs where a Boolean value is required. LIKE is considered a predicate \tn % Row Count 16 (+ 9) % Row 3 \SetRowColor{white} \% & match any number of occurrences (including 0)of any character. Basically, it substitutes any type and number of characters. However, it does not match NULL. \tn % Row Count 21 (+ 5) % Row 4 \SetRowColor{LightBackground} \_ & it matches a single character. It is not supported by DB2. \tn % Row Count 23 (+ 2) % Row 5 \SetRowColor{white} {[}{]} & used to specify a set of characters, any of which must match a character in the specified position. Sets are not supportes in MySQL, Oracle, DB2, and SQLite \tn % Row Count 28 (+ 5) % Row 6 \SetRowColor{LightBackground} \textasciicircum{} & negates the meaning of a wildcard. For example, '{[}\textasciicircum{}JM{]}\%'. \tn % Row Count 30 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{These types of searches may be case sensitive depending on the DBMS. \newline Wildcards are rarely positioned in the middle of a search pattern, but there is a situation no included in this case which is looking for email addresses \newline Some DBMS may add blank spaces to the end of each string in a cell, if this is the case in your DBMS, add \% at the end of each search pattern. \newline Tips: \newline - Don't overuse wildcards \newline - Try not to use wildcards at the beggining of the search pattern, it turns it very slow} \tn \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}{Summarizing Data}} \tn % Row 0 \SetRowColor{LightBackground} Aggregate functions & functions that operate on a set of rows to calculate and return a single value. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} AVG(column) & returns a column's average value. NULL values are ignored by this function. \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} COUNT(column) & returns the number of row in a column. COUNT(*) to count the number of rows in a table. COUNT(column) count the number of rows which have a value, thus ignoring NULL values. \tn % Row Count 17 (+ 9) % Row 3 \SetRowColor{white} MAX(column) & returns a comlumn's highest value. It ignores NULL values. \tn % Row Count 20 (+ 3) % Row 4 \SetRowColor{LightBackground} MIN(column) & returns the sum if a column's value. It ignores NULL values. \tn % Row Count 23 (+ 3) % Row 5 \SetRowColor{white} SUM(column) & returns the sum of a column's values. It ignores NULL values.. \tn % Row Count 27 (+ 4) % Row 6 \SetRowColor{LightBackground} TOP (only applies to some DBMSs) & lets you perform calculations on subsets of query results. \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Summarizing Data (cont)}} \tn % Row 7 \SetRowColor{LightBackground} TOP PERCENT (only applies to some DBMSs) & lets you perform calculations on subsets of query results. \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{To calculate multiple averages, we have to use multiple AVG(). \newline In some DBMSs, MAX()/MIN() can be used with multiple columns, in this case, it will return the highest/lowest value of all columns. \newline We can pass DISTINCT, in between the paretheses, on these functions so we only apply them to distinct values. The DISTINCT can only be used with \_COUNT when a column name is specified.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}