- Importing Excel files
External Data > New Data Source > From File > Excel
- Running SQL queries
Create > Query Design > SQL View
- Main SQL statements
- SELECT - retrieves data from one or more tables. It allows you to specify which columns you want to retrieve and may include optional clauses such as WHERE, ORDER BY, GROUP BY, HAVING, and LIMIT to filter, sort, group, and limit the results.
SELECT column1, column2 FROM table_name WHERE condition;
INSERT - adds new records (rows) to a table
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATE - modifies existing records in a table
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
DELETE - removes records from a table
remove records from a table
CREATE - createSnew database objects such as tables, views, indexes, or stored procedures
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
ALTER - modifies the structure of existing database objects such as tables (e.g., add or drop columns)
ALTER TABLE table_name ADD column_name datatype;
DROP - deleteS existing database objects such as tables, views, or indexes
DROP TABLE table_name;
Main SQL wildcards
- percentage (%) - any sequence of zero or more characters
- underscore (_) - any single character
- square brackets ([ ]) - a set or range of characters. For example, [aeiou] would match any single lowercase vowel, and [0-9] would match any single digit.
Note: use [ ] to search for wildcards such as '?' as in [?].
- Caret (^) - when used inside square brackets, negates the character set. For example, [^aeiou] would match any single character that is not a lowercase vowel.
- Question Mark (?) - some database systems support the question mark (?) wildcard as a placeholder for a single character, similar to the underscore (_) wildcard.
- Braces ({ }) - a set of options for a single character. For example, {cat, dog, rat} would match any of the specified options.
- Pipe (|) - alternatives in a pattern like the OR operator. For example, cat|dog would match either 'cat' or 'dog'.
Operators
- AND - combines two or more conditions. It returns true only if all the conditions separated by AND are true.
SELECT * FROM employees
WHERE department = 'Sales' AND salary > 50000;
OR - combines two or more conditions. It returns true if any of the conditions separated by OR is true.
SELECT * FROM students
WHERE grade = 'A' OR grade = 'B';
Combining AND and OR Operators - creates more complex conditions
SELECT * FROM orders
WHERE (product = 'Laptop' AND quantity >= 2) OR (product = 'Tablet' AND quantity >= 5);
IN - specifies multiple values in a WHERE clause. It allows you to include multiple values in a single condition.
SELECT * FROM products
WHERE category IN ('Electronics', 'Clothing', 'Books');
NOT - negates a condition. It reverses the result of a logical expression.
SELECT * FROM employees
WHERE NOT department = 'HR';
LIKE - for pattern matching in SQL. It allows you to search for a specified pattern in a column.
SELECT * FROM customers
WHERE last_name LIKE 'Sm%';
BETWEEN - specifies a range of values in a WHERE clause. It is inclusive, meaning it includes both the start and end values.
SELECT * FROM orders
WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31';
Comparison operators - compare values in SQL queries
- Equal to: =
- Not equal to: <> or !=
- Greater than: >
- Greater than or equal to: >=
- Less than: <
- Less than or equal to: <=