Basics of SQL 1
Basics of SQL 1
Basics of SQL 1
❖Overview of Databases
❖Relational Databases
❖Query Categories
AGENDA ❖Key Words and Some Basic SQL Functions
❖Joining Tables
Relational Databases (SQL) Store data in a structured format with rows and columns. MySQL, Oracle, PostgreSQL, Microsoft SQL Server
NoSQL Databases that store data in documents, usually in
NoSQL Databases MongoDB, Cassandra, Redis, Couchbase
formats like JSON.
NoSQL Databases that store data as pairs of keys and
Graph Databases Neo4j, OrientDB, ArangoDB
values.
NoSQL Databases that store data in tables, rows, and
Document-Oriented Databases MongoDB, CouchDB
dynamic columns.
NoSQL Databases that are designed to handle data whose
Key-Value Stores Redis, Amazon DynamoDB, Riak
relations are best represented as a graph.
Wide-Value Stores Store data in a structured format with rows and columns. Apache Cassandra, Google’s Bigtable, HBase
RELATIONAL DATABASES
o A relational database is a type of database that
organizes data in predefined relationships where data is
stored in one or more tables (or "relations") of columns
and rows, making it easy to see and understand how
different data structures relate to each other.
o GROUP BY: Groups rows that have the same values in specified
columns.
Definition: Returns all rows when there is a match in one of the tables. If there is no match, NULL values are
returned for columns from the table without a match.
Use Case: Used when you want to include all records from both tables, regardless of whether there is a match.
SELECT columns
FROM table1
FULL JOIN table2
ON table1.common_column = table2.common_column;
SELF JOIN
Definition: A self join is a regular join, but the table is joined with itself.
Use Case: Used to query hierarchical data or compare rows within the same table.
SELECT a.columns, b.columns
FROM table a, table b
WHERE condition;
Syntax: Syntax:
SELECT column1, SELECT column1, column2
column2 FROM table_name
FROM table_name; WHERE condition;
WRITING BASIC
Example: Example:
SQL QUERIES SELECT name, SELECT name, age FROM
age students WHERE age > 18;
FROM students;
SOME SQL BEST PRACTICES
Writing Readable Queries Limit the use of subqueries Write Efficient WHERE Clauses
❖ Next Steps
exploration