0% found this document useful (0 votes)
52 views

SQL Cheat Sheet: Section 1

This SQL cheat sheet provides an overview of key SQL concepts and functions organized into 6 sections: 1. Covers basic concepts like SELECT statements, aliases, arithmetic operations, and data types. 2. Discusses SELECT statements in more detail including DISTINCT, BETWEEN, IN, LIKE, comparison operators, and ORDER BY. 3. Explains logical operators AND and OR and functions for conversions, dates, characters, numbers, and aggregating multiple rows. 4. Details date functions, character manipulation functions, and the DUAL table for testing. 5. Lists common data types. 6. Compares different types of joins including NATURAL JOIN, CROSS JOIN, and JOIN

Uploaded by

Natalia Oliva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

SQL Cheat Sheet: Section 1

This SQL cheat sheet provides an overview of key SQL concepts and functions organized into 6 sections: 1. Covers basic concepts like SELECT statements, aliases, arithmetic operations, and data types. 2. Discusses SELECT statements in more detail including DISTINCT, BETWEEN, IN, LIKE, comparison operators, and ORDER BY. 3. Explains logical operators AND and OR and functions for conversions, dates, characters, numbers, and aggregating multiple rows. 4. Details date functions, character manipulation functions, and the DUAL table for testing. 5. Lists common data types. 6. Compares different types of joins including NATURAL JOIN, CROSS JOIN, and JOIN

Uploaded by

Natalia Oliva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL Cheat Sheet

From 1.1 to 6.2


Section 1
Caution with spelling -> ERROR
SELECT * -> Returns all the rows in a table
Alias (AS) + arithmetic operations
table | column | row | field | primary key |foreign key
NULL -> unavailable, unassigned, unknown, or inapplicable

Section 2
(Or DESC) -> returns the table name, data types, pk, fk, and null columns
DISTINCT Concatenation
Eliminate diplicate rows
SELECT DISTINCT <colum_name>

BETWEEN <value> AND <value>


IN (<value1>,<value2>)
WHERE <colum> + LIKE '_<char>%'*
*'_ 'one char IS NULL
Comparasion operators (case sensitive)
'%' multiple char IS NOT NULL
Section 3 ESCAPE + special char

AND -> Returns TRUE if both conditions are true FUNCTIONS


OR -> Returns TRUE if either condition is true
SINGLE ROW
NOT -> Returns TRUE if the condition is false
conversion, date,
ORDER BY general, char.

MULTIPLE ROW
many rows -> single
MAX: Highest value
DESC |Alias | other <colum> not called
MIN: Lowest value
multiple <colum>
AVG: Average value

Section 4
DUAL TABLE not directly related to database table
CONVERT
MONTH_BETWEEN (2 dates)
<convert> (<colum_name>) SYSDATE ADD_MONTH
LOWER -> to lower-case DATE FUNCTIONS NEXT_DAY (of specified)
UPPER -> to upper.case LAST_DAY (of the month)
ROUND, TRUNC
INTCAP -> first letter upper
CHARACTER MANIPULATION FUNCTIONS (+ alias)

NUMBER FUNCTIONS
ROUND -> round numbers
TRUNC -> terminate number
MOD -> finds the reminder (odd or even)

Same with TRUNC,MOD| If decimal not specified =0


*
Section 5 *Trailing, both

Varchar2 | Char | Number | Date


NVL (Replace)
NVL2 (If 1 value -> 2, If 1 null -> 3
NULL FUNCTIONS
2 1 NULL IF (compare, equal = null)
COALESCE (NVL with multiple values)

3 4

1 *
2
3
*YY -> this century
4 RR -> not this century

fx -> Requires exact matching between the character data and the format model.
Section 6 fm -> Returns a value with no leading or trailing blanks.

NATURAL JOIN -> 2 Tables, matches colums & rows with equal value and name. (diferent data type -> ERROR)
CROSS JOIN -> joins each row in one table to every row in the other table.
JOIN... ON (...)
JOIN ... USING (...) Adding 2 tables without matching columns
Could use non-equality operators
(Between... and)
Avoids natural join error
Should not have alias o table name in the statement
Both (using and on) could be used to join three tables or more

More informaton on www.myacademyoracle.com


Andrea Morales Mata

You might also like