\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{lauragomezp} \pdfinfo{ /Title (mysql.pdf) /Creator (Cheatography) /Author (lauragomezp) /Subject (MySQL 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}{A31443} \definecolor{LightBackground}{HTML}{F9F0F3} \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{MySQL Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{lauragomezp} via \textcolor{DarkBackground}{\uline{cheatography.com/198964/cs/42158/}}} \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}lauragomezp \\ \uline{cheatography.com/lauragomezp} \\ \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 22nd January, 2024.\\ 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.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Consultas básicas}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{SELECT campo FROM tabla}} & Consulta básica \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{SELECT DISTINCT}} & Consulta eliminando los campos repetidos \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{SELECT campo AS alias}} & Renombra un campo \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{WHERE condición}} & Almacena los criterios \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{ORDER BY campo {[}DESC | ASC{]}}} & Ordena por uno o varios campos \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} {\bf{GROUP BY campo}} & Cuenta filas por cada grupo de valores que coincidan \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{HAVING condición}} & Filtra los resultados después de agrupar \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} {\bf{LIMIT número}} & Limita el número de filas \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{=}} & Igual \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{!=}} & No igual \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{\textless{}, \textless{}=}} & Menor que y menor o igual que \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} {\bf{\textgreater{}, =\textgreater{}}} & Mayor que y mayor o igual que \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{is null}} & Que el campo sea nulo \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} {\bf{is not null}} & Que el campo no sea nulo \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{*}} & Multiplicar \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} {\bf{+}} & Sumar \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} {\bf{-}} & Restar \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} {\bf{/}} & Dividir \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} {\bf{\%}} & Resto entero de la operación \tn % Row Count 15 (+ 2) % Row 11 \SetRowColor{white} {\bf{and}} & Condición y condición \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{LightBackground} {\bf{or}} & Condición o condición \tn % Row Count 17 (+ 1) % Row 13 \SetRowColor{white} {\bf{between}} & Entre valor AND valor \tn % Row Count 18 (+ 1) % Row 14 \SetRowColor{LightBackground} {\bf{IN (valor, valor)}} & Sirve como un OR para valores \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Búsqueda}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{USE database}} & Utilizar base de datos \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{SHOW DATABASES}} & Mostrar las bases de datos existentes \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{SHOW TABLES}} & Mostrar las tablas de la base de datos \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Funciones de agregación}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{max()}} & Devuelve el valor más bajo \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{min()}} & Devuelve el valor más alto \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{count()}} & Cuenta todas las filas \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{count(distinct)}} & Cuenta las filas diferentes \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{avg()}} & Devuelve la media \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} {\bf{sum()}} & Devuelve el resultado de la suma \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{group\_ concat()}} & Agrupa cadenas de caracteres en una sola línea \tn % Row Count 10 (+ 2) \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}{Funciones de fecha}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{year()}} & Devuelve un entero con el año \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{month()}} & Devuelve un entero con el mes \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{day()}} & Devuelve un entero con el día \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{timestampdiff (CONCEPTO, fecha,fecha)}} & Calcula la diferencia entre dos fechas según el concepto (YEAR, MONTH, DAY) \tn % Row Count 10 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{curdate()}} & Devuelve la fecha actual \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} {\bf{dateadd(date, interval CONCEPTO)}} & Añade una cantidad concreta de tiempo a una fecha \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{weekday()}} & 0 lunes - 6 domingo \tn % Row Count 16 (+ 1) % Row 7 \SetRowColor{white} {\bf{dayofweek()}} & 1 domingo - 7 sábado \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{date\_format (fecha, formato)}} & Establece formato utilizando operadores de cadena \tn % Row Count 21 (+ 3) \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}{Funciones de varchar}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{length()}} & Devuelve la longitud de la cadena \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{concat()}} & Recibe parámetros y los une en una sola cadena \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{substring (1,2,3)}} & 1) La cadena 2) La posición desde donde se va a seleccionar 3) los caracteres que se seleccionan \tn % Row Count 10 (+ 5) % Row 3 \SetRowColor{white} {\bf{substring \_index (1,2,3)}} & 1) La cadena 2) el parámetro de parada 3) La posición \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{locate(char, cadena)}} & Devuelve un int que indica la posición del char en la cadena \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} {\bf{lower()}} & Cambia una cadena a minúscula \tn % Row Count 18 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{upper()}} & Cambia una cadena a mayúsculas \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} {\bf{reverse()}} & Invierte la cadena \tn % Row Count 21 (+ 1) % Row 8 \SetRowColor{LightBackground} {\bf{replace (1,2,3)}} & 1) Cadena de búsqueda 2) La cadena a sustituir 3) La cadena que la sustituye \tn % Row Count 25 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operador LIKE}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{WHERE campo LIKE "cadena"}} & Estructura básica \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{"\%"}} & Se sustituye por un número de caracteres cualquiera \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{"\_"}} & Se sustituye por un solo carácter cualquiera \tn % Row Count 7 (+ 2) \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}{Funciones numéricas}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{abs()}} & Devuelve el valor absoluto de un entero \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{sqrt()}} & Devuelve la raíz cuadrada \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{ceil()}} & Redondea hacia arriba \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} {\bf{round (int,int)}} & Redondea al más cercano. El segundo parámetro es el número de decimales \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{truncate (int, int)}} & Devuelve el número con los decimales del segundo parámetro \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} {\bf{greatest()}} & Devuelve el mayor campo \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}