SQL Queries
SQL (Structured Query Language) is a standard language used to manage and manipulate relational databases. Here are some examples of SQL queries:
SELECT statement
SELECT column1, column2, ... FROM table_name;
For example, if you want to retrieve all the columns from a table named "customers", the query would look like this:
SELECT * FROM customers;
WHERE clause
SELECT column1, column2, ... FROM table_name WHERE condition;
For example, if you want to retrieve all the customers who are from New York, the query would look like this:
SELECT * FROM customers WHERE city = 'New York';
JOIN clause
SELECT column1, column2, ... FROM table1 JOIN table2 ON table1.column_name = table2.column_name;
For example, if you have two tables named "orders" and "customers" and you want to retrieve all the orders placed by customers from New York, the query would look like this:
SELECT orders.order_id, orders.order_date, customers.customer_name FROM orders JOIN customers ON orders.customer_id = customers.customer_id WHERE customers.city = 'New York';
ER Diagrams
An ER (Entity-Relationship) diagram is a visual representation of the tables, columns, and relationships in a database. ER diagrams are useful for understanding the structure of a database and for planning and designing new databases. Here are some common symbols used in ER diagrams:
- Entity: represents a table in the database
- Attribute: represents a column in a table
- Relationship: represents a connection between two tables
ER diagrams can be created using various software tools, such as Lucidchart, Microsoft Visio, and MySQL Workbench.