\documentclass[11pt,twocolumn]{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{alltt}
\usepackage{hyperref}

\hypersetup{colorlinks=true}

\textheight = 9 in
\oddsidemargin = 0.0 in
\evensidemargin = 0.0 in
\topmargin = 0.0 in
\headheight = 0.0 in
\headsep = 0.0 in
\parskip = 5pt
\parindent = 0.0in

%\setlength{\hoffset}{-65pt}
%\setlength{\voffset}{-65pt}
\newcommand{\ttnrbf}[1]{\textnormal{\textbf{#1}}}
\newcommand{\ttitbf}[1]{\textnormal{\textbf{#1}}}
\newcommand{\ttit}[1]{\textit{#1}}
\newcommand{\sSecBox}[1]{\begin{minipage}{3in}\begin{alltt}{\small\textrm{\textbf{#1}}}}
\newcommand{\eSecBox}{\end{alltt}\end{minipage}}
\newcommand{\srb}[2]{\parbox[t]{#1}{#2}\rule{5pt}{0pt}}

\newcommand{\blt}{\(\bullet\)}

\begin{document}
\pagestyle{empty}

\fbox{{\parbox[b]{2.5in}{\huge \bf SQL \\ \tiny \copyright 1999-2016 Mitch Richling \url{https://www.mitchr.me}  \\ Last Updated 2016-07-09}}}
\tiny

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{SELECT}
SELECT [ ALL | DISTINCT ]
  [ [ * ] | [ expression [ AS output_name ] ] ] [, ...] 
[ INTO TABLE new_table ]
[ FROM [ [ [ ONLY ] table_name ] | 
         [ ( select ) [ AS ] alias ] | 
         [ join_table ]
       ] [, ...]
[ WHERE condition ] 
[ GROUP BY expression [, ...] ] 
[ HAVING condition [, ...] ] 
[ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] 
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] 
[ LIMIT { count | ALL } ] 
[ OFFSET start ] 
\eSecBox

\sSecBox{INSERT}
INSERT INTO table [ ( column [, ...] ) ] 
   [ VALUES ( expression [, ...] ) | 
     SELECT query
   ]
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{JOIN} 
Join clauses may only appear in a FROM section.  Logically,
join clauses take two tables, or expressions returning
tables, and combines them into one table.

Syntax: 

   from_item 
     [ NATURAL ] join_type 
   from_item 
   [ ON join_condition | USING ( join_column_list ) ] 

join_type is one of: 
   \blt [ INNER ] JOIN        Rows matching criteria
   \blt LEFT [ OUTER ] JOIN   INNER+all on left
   \blt RIGHT [ OUTER ] JOIN  INNER+all on right
   \blt FULL [ OUTER ] JOIN   all on left or right
   \blt CROSS JOIN.           Rows in the cross product

Exactly one of NATURAL, ON join_condition, or USING (
join_column_list ) must appear for INNER and OUTER join
types.  For CROSS JOIN, none of these items may appear.
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{CREATE TABLE}
CREATE
TABLE table_name ( [ column_name 
                     data_type 
                     [ DEFAULT default_expr ] 
                     [ column_constraint [, ... ] ] | 
                     table_constraint 
                    ] [, ... ] ) 

column_constraint is: 
[ CONSTRAINT constraint_name ] 
   [ NOT NULL | 
     NULL | 
     UNIQUE | 
     PRIMARY KEY | 
     CHECK (expression) | 
     REFERENCES reftable [ ( refcolumn ) ]  
       [ ON DELETE action ] 
       [ ON UPDATE action ] 
   ] 


table_constraint is:
[ CONSTRAINT constraint_name ] 
   { UNIQUE ( column_name [, ... ] ) | 
     PRIMARY KEY ( column_name [, ... ] ) | 
     CHECK ( expression ) | 
     FOREIGN KEY ( column_name [, ... ] ) 
       REFERENCES reftable [ ( refcolumn [, ... ] ) ]  
       [ ON DELETE action ] 
       [ ON UPDATE action ] }
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{CREATE VIEW}
CREATE [ OR REPLACE ] 
VIEW view [ ( column name list ) ] AS SELECT query 
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{Types}
\blt NUMERIC(precesion [,scale])
\blt character varing(n) _or_ varchar(n)
\blt character(n) _or_ char(n)
\blt date
\blt time
\blt timestamp
\blt text (PostgreSQL)
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{Expression Functions \& Operators}
NOTE: n,m=integer, s,s1,s2=string
\blt abs(n)     \blt random(n)    \blt round(n [,m])
\blt ceil(n)    \blt sign(n)      \blt trunc(n [,m])
\blt floor(n)   \blt sqrt(n)      \blt char_length(s)
\blt lower(s)   \blt substr(n, n) \blt position(s1, s2)
\blt upper(s)   \blt length(s)    \blt repeat(s, m)
\blt strpos(s1, s2)
\blt replace(s FROM s1 TO s2)
\blt substring(s [FROM m] [FOR n])
\blt trim([LEADING | TRAILING | BOTH] [s] FROM s)
\blt Arithmatic: +, -, /, *, ^, % (mod)
\blt String Concatenation: ||
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{TO\_CHAR}
General use: to_char(<thing_to_format>, <format_string>)
For numbers:
   \blt  9 -- Digits              \blt 0 -- Leading zeros
   \blt  . -- decimal point       \blt D -- decimal point
   \blt  , -- group seporater     \blt G -- group seporator
   \blt PR -- negative with <>    \blt S -- negative with -
   \blt MI -- minus sign          \blt PL -- plus sign
   \blt  L -- currency symbol
For dates:
    \blt Month|month -- Month name       \blt D   -- day of week (SUN=1) 
    \blt MON|Mon|mon -- month abrv       \blt W   -- week of month       
    \blt MM          -- month of year    \blt WW  -- week of year        
    \blt DAY|Day|day -- Day abrv         \blt IW  -- ISO week number     
    \blt DY|Dy|dy    -- Day abrv         \blt CC  -- century             
    \blt DDD         -- day of year      \blt J   -- Julian day          
    \blt DD          -- day of month     \blt Q   -- quarter             
    \blt TZ|tz       -- Time zone           
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{CASE}
Case is an EXPRESSION, so it can be used lots of places
Syntax:
CASE WHEN condition THEN result
     [WHEN ...]
     [ELSE result]
END
\eSecBox


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{Condition Operators}
\blt Logic: and, or, not
\blt Comparison: <, >, <=, >=, =, <>, !=
\blt \ttit{expression} IS NULL
\blt \ttit{expression} IS NOT NULL
\blt \ttit{expression} IN (value[, ...])
\blt \ttit{expression} IN (\ttit{subquery})
\blt \ttit{expression} NOT IN (value[, ...])
\blt \ttit{expression} NOT IN (\ttit{subquery})
\blt \ttit{expression} \ttit{operator} ANY (\ttit{subquery})
\blt \ttit{expression} \ttit{operator} SOME (\ttit{subquery})
\blt \ttit{expression} \ttit{operator} ALL (\ttit{subquery})
\blt \ttit{expression} BETWEEN \ttit{expression} AND \ttit{expression} 
\blt \ttit{expression} NOT BETWEEN \ttit{expression} AND \ttit{expression} 
\blt EXISTS(\ttit{subquery})
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{Agregrate Functions}
\blt avg      \blt count      \blt max
\blt min      \blt sum        \blt std-dev
\blt variance
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{Oracle Data Dictionary}
\blt [user_|all_|dba_]tables
     owner, table_name, tablespace_name, cluster_name, num_rows, 
     avg_row_len
\blt all_tab_columns
     owner, table_name, column_name, data_type, data_type_mod,
     data_type_owner, data_length, data_precision, data_scale, nullable,
     column_id, default_length, data_default, num_distinct, low_value,
     high_value, density, num_nulls
\blt all_cons_columns
     owner, constraint_name, table_name, column_name
\blt all_indexes 
     owner, index_name, index_type, table_owner, table_name, table_type, 
     uniqueness, tablespace_name
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{Oracle SQLPlus}
\blt Quit                         exit
\blt Run commands from a file:    \@<file_name>
\blt sp[ool] \{filename | off | out \} -- Spool output to file
\blt set auto[commit] \{on|\underline{off}|immediate|<statement_count>\}
\blt set echo \{on|\underline{off}\}
\blt set feed[back] \{on|\underline{off}\}
\blt set hea[ding] \{\underline{on}|off\}
\blt set mark[up] entmap \{\underline{on}|off\}  -- do the right HTML thing for <, >, etc
\blt set mark[up] pre[format] \{on|\underline{off}\}  -- use /pre tags in HTML
\blt set NULL text -- what to display for nulls
\blt set numf[ormat] text -- format for numbers
\blt set linesize NNN
\blt set pagesize NNN
\blt set pau[se] \{on|\underline{off}\}  -- pause for pages or not
\blt set recsepchar text -- what to use for record seporator
\blt set space NNN -- number of spaces between columns
\blt set tab \{\underline{on}|off\} -- use tabs or spaces
\blt set term[out] \{\underline{on}|off\} -- display results from script fiels on display
\blt set timi[ng] \{on|\underline{off}\} -- display time for commands
\blt set trim[out] \{\underline{on}|off\} -- trim trailing spaces from lines
\blt set trims[pool] \{on|\underline{off}\} -- trim trailing spaces from spooled output
\blt set tru[ncate] \{on|\underline{off}\} -- truncate long lines
\blt set wra[p] \{\underline{on}|off\} -- wrap or trim long lines
\blt describe <foo> -- print info about the object <foo>
\eSecBox

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sSecBox{PostgreSQL psql}
{\blt \verb+\l+        }List tables
{\blt \verb+\i+ \ttit{file}   }Run commands from given file
{\blt \verb+\H+        }Toggle HTML output
{\blt \verb+\q+        }Quit
{\blt \verb+\d+ \ttit{name}   }Describe table, index, sequence, or view
{\blt \verb+\a+        }Toggle between aligned and unaligned output mode
{\blt \verb+\f+ \ttit{string} }Show/set field separator
{\blt \verb+\h+ \ttit{name}   }Get help for SQL commands
{\blt \verb+\o+ \ttit{file}   }Send query results to file
{\blt \verb+\o+ \ttit{|pipe}  }Send query results to pipe
 
\eSecBox


 \end{document}
