In this post, we’ll cover some quick notes on SQL, including relational and non-relational databases, and various SQL queries and operators.
Relational Database: A database structured to recognize relations among stored items of information.
Non-Relational Database: A database that does not use a tabular schema of rows and columns.
SQL: A domain-specific language used in programming and designed for managing data in relational databases. It was initially developed by IBM.
Retrieving Data from a Single Table:
SELECT DISTINCTto retrieve unique items.
- Mathematical operators can be used in the
SELECT * FROM Customers WHERE state IN ('VA', 'FL', 'GA')
BETWEENoperator: selects values within a given range (inclusive).
LIKEoperator: pattern matching with
REGEXP: pattern matching with regular expressions.
IS NULL: to filter records with null values.
ORDER BY: to sort records by a specified column.
LIMIT: to limit the number of records returned.
Retrieving Data from Multiple Tables:
INNER JOIN: combines records from two or more tables.
SELF JOIN: joins a table to itself.
- Joining multiple tables with compound join conditions.
- Implicit join syntax:
SELECT * FROM orders o, customers c WHERE o.customer_id = c.customer_id
OUTER JOIN: two types –
SELF OUTER JOIN: an outer join involving a table with itself.
USING: to specify columns for comparison in a join.
NATURAL JOIN: to join two tables based on columns with the same name and compatible data types.
UNION: combines the results of two or more queries.
These quick notes should help you get started with SQL and provide a basic understanding of how to write and execute SQL queries. As you gain experience, you’ll be able to explore more advanced features and techniques to manage your data effectively.