๐๏ธ Intoduction
<ThemedImage
๐๏ธ Select
The SELECT keyword is used to retrieve specific columns or data from a database table. It allows you to specify what data you want to fetch, such as all columns (SELECT *) or specific ones (SELECT column1, column2). This is the first step in most SQL queries.
๐๏ธ From
The FROM keyword specifies the table from which the data should be retrieved. It defines the source of your query and works together with SELECT to determine where the data comes from.
๐๏ธ Join
The JOIN (or INNER JOIN) keyword is used to combine rows from two or more tables based on a related column. By joining tables, you can retrieve data spread across multiple tables and analyze it as a single dataset.
๐๏ธ Left Join
A LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table and the matching rows from the right table. If no match exists in the right table, the result will include NULL values for the right table's columns.
๐๏ธ Right Join
A RIGHT JOIN (or RIGHT OUTER JOIN) is the opposite of a LEFT JOIN. It returns all rows from the right table and the matching rows from the left table. If no match exists, NULL values are included for the left table's columns.
๐๏ธ Where
The WHERE clause filters rows from the table or tables based on a specified condition. It allows you to retrieve only the rows that meet the condition, such as WHERE age > 30 to get rows where the age column has values greater than 30.
๐๏ธ Group by
The GROUP BY clause groups rows that have the same values in specified columns into summary rows. For example, you can group sales data by product_id to calculate totals or averages for each product.
๐๏ธ Having
The HAVING clause is used to filter grouped data after applying the GROUP BY clause. It works like WHERE, but it applies to aggregated data, such as HAVING SUM(sales) > 1000 to show groups with total sales above 1000.
๐๏ธ Order By
The ORDER BY clause is used to sort the rows in the result set by one or more columns, either in ascending (ASC) or descending (DESC) order. For example, ORDER BY name ASC sorts by name alphabetically.
๐๏ธ Limit
The LIMIT clause restricts the number of rows returned in the result set. For example, LIMIT 10 retrieves only the first 10 rows, which is useful for performance and pagination in large datasets.
๐๏ธ SQL Cheat Sheet
SQL Cheat Sheet Click here