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

Multi currency entry in tally

 In Tally, handling multi-currency entries allows you to record transactions involving foreign currencies. This feature is particularly useful for businesses that deal with international transactions or have accounts in different currencies. Here's how you can enable and use multi-currency entry in Tally: **Enabling Multi-Currency Feature**: 1. Go to Gateway of Tally (Home Screen). 2. Press F11 or click on "F11: Features" from the right sidebar. 3. In the Features screen, go to "F1: Accounting Features." 4. Under "Forex and Multi-Currency," set "Enable" to "Yes." 5. Save the settings. **Configuring Currency Rates**: 1. In the Gateway of Tally, click on "Accounts Info." 2. Select "Currencies" and then "Create." 3. Enter the currency details like symbol, name, formal name, etc. 4. Specify the "Standard Rates" for the currency against your base currency (usually your local currency). 5. Save the ...