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

 

About all version of tally

 Tally is a popular accounting software developed by Tally Solutions Pvt. Ltd. It is widely used for accounting, financial management, inventory management, and taxation purposes. As of my knowledge cutoff in September 2021, here are some of the major versions of Tally: 1. **Tally 4.5**: This was one of the early versions of Tally released in the 1990s. It offered basic accounting features and was primarily used for simple bookkeeping tasks. 2. **Tally 5.4**: Released in the late 1990s, Tally 5.4 introduced several improvements and additional functionalities to cater to the evolving needs of businesses. 3. **Tally 6.3**: This version brought significant enhancements to Tally's capabilities, including support for Value Added Tax (VAT) and various other statutory requirements. 4. **Tally 7.2**: Launched in 2005, Tally 7.2 further expanded Tally's features, making it more robust and user-friendly. It introduced support for multiple currencies and multiple companies. 5. **Tally 8.1...