Skip to main content

SQL Cheat Sheet

SQL cheat sheet with explanations for each command:


1. SELECT: Retrieve data from a database table.

   Example: `SELECT column1, column2 FROM table_name;`


2. DISTINCT: Remove duplicate rows from the result set.

   Example: `SELECT DISTINCT column FROM table_name;`


3. WHERE: Filter rows based on specific conditions.

   Example: `SELECT * FROM table_name WHERE column = value;`


4. AND / OR: Combine multiple conditions in a WHERE clause.

   Example: `SELECT * FROM table_name WHERE condition1 AND condition2;`


5. ORDER BY: Sort the result set based on one or more columns.

   Example: `SELECT * FROM table_name ORDER BY column ASC;`


6. GROUP BY: Group rows based on specified columns (usually used with aggregate functions).

   Example: `SELECT column, COUNT(*) FROM table_name GROUP BY column;`


7. HAVING: Filter groups of rows based on aggregate function results.

   Example: `SELECT column, COUNT(*) FROM table_name GROUP BY column HAVING COUNT(*) > 5;`


8. JOIN: Combine data from multiple tables based on a condition.

   Example: `SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;`


9. INNER JOIN: Return only the matched rows from both tables.

   Example: `SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column;`


10. LEFT JOIN: Return all rows from the left table and matched rows from the right table.

    Example: `SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column;`


11. RIGHT JOIN: Return all rows from the right table and matched rows from the left table.

    Example: `SELECT * FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;`


12. FULL OUTER JOIN: Return all rows when there is a match in either table.

    Example: `SELECT * FROM table1 FULL OUTER JOIN table2 ON table1.column = table2.column;`


13. UNION: Combine the result of two or more SELECT statements (removes duplicates).

    Example: `SELECT column1 FROM table1 UNION SELECT column1 FROM table2;`


14. UNION ALL: Combine the result of two or more SELECT statements (includes duplicates).

    Example: `SELECT column1 FROM table1 UNION ALL SELECT column1 FROM table2;`


15. INSERT INTO: Insert new records into a table.

    Example: `INSERT INTO table_name (column1, column2) VALUES (value1, value2);`


16. UPDATE: Modify existing records in a table.

    Example: `UPDATE table_name SET column = new_value WHERE condition;`


17. DELETE: Remove records from a table.

    Example: `DELETE FROM table_name WHERE condition;`


18. CREATE TABLE: Create a new table with specified columns and data types.

    Example:

    ```sql

    CREATE TABLE table_name (

        column1 datatype1,

        column2 datatype2,

        ...

    );

    ```


19. ALTER TABLE: Modify an existing table by adding or altering columns.

    Example: `ALTER TABLE table_name ADD column datatype;`


20. DROP TABLE: Delete an existing table.

    Example: `DROP TABLE table_name;`


Please note that the examples provided are simplified, and you may need to adjust them based on your specific database structure and data. SQL is a powerful language for working with relational databases, and these commands cover the most common operations.

Comments

Popular posts from this blog

Microsoft Word 2010 Shortcut Key in Gujarati

Microsoft Word 2010 Shortcut key in Gujarati

1BHK & 2BHK in BHUJ More Detail - Ahesan Sumra - 98796 87217

 

Full detail About OGads

 OGAds (Olymp Trade Affiliates) is an affiliate marketing platform that focuses on the mobile and desktop performance marketing industry. It primarily deals with content locking, which is a method of monetizing content by offering users access to locked content or downloads in exchange for completing a specified action, such as filling out a survey or installing an app. Here are some key details about OGAds: 1. **Affiliate Network**: OGAds is a well-established affiliate network that connects affiliates (publishers) with advertisers (product owners or app developers). Affiliates promote offers, and when users complete the desired action, the affiliate earns a commission. 2. **Monetization Methods**: The primary monetization method used by OGAds is Content Locking. They provide tools for affiliates to lock premium content behind a survey or app installation wall, encouraging users to take specific actions to access the content. 3. **Mobile and Desktop Offers**: OGAds offers a variet...