Skip to main content

SQL QUERY

MySQL is a popular relational database management system used to store and manage data. Here are some common SQL queries with examples and explanations:


1. SELECT Query:

   - Example: `SELECT * FROM employees;`

   - Explanation: This query retrieves all columns (`*`) from the "employees" table, returning all rows.


2. WHERE Clause:

   - Example: `SELECT * FROM employees WHERE department = 'HR';`

   - Explanation: This query retrieves all columns from the "employees" table where the "department" column has the value 'HR'.


3. ORDER BY Clause:

   - Example: `SELECT * FROM employees ORDER BY salary DESC;`

   - Explanation: This query retrieves all columns from the "employees" table and sorts the result in descending order based on the "salary" column.


4. INSERT INTO Query:

   - Example: `INSERT INTO employees (name, age, department) VALUES ('John Doe', 30, 'IT');`

   - Explanation: This query inserts a new record into the "employees" table with specified values for the "name", "age", and "department" columns.


5. UPDATE Query:

   - Example: `UPDATE employees SET salary = 50000 WHERE department = 'Finance';`

   - Explanation: This query updates the "salary" column to 50000 for all rows in the "employees" table where the "department" column has the value 'Finance'.


6. DELETE Query:

   - Example: `DELETE FROM employees WHERE age > 60;`

   - Explanation: This query deletes all rows from the "employees" table where the "age" column is greater than 60.


7. JOIN Clause:

   - Example: `SELECT employees.name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.id;`

   - Explanation: This query retrieves the "name" column from the "employees" table and the "department_name" column from the "departments" table, joining them based on the "department_id" and "id" columns, respectively.


These are just a few examples of MySQL queries. Remember that SQL syntax may vary slightly depending on the specific database system you are using, but the principles remain consistent.

Comments

Popular posts from this blog

Microsoft Word 2010 Shortcut Key in Gujarati

Microsoft Word 2010 Shortcut key in Gujarati

Power Point Shortcut key

Below is a list of common PowerPoint shortcut keys along with their details: 1. New Presentation: Ctrl + N    - Creates a new, blank PowerPoint presentation. 2. Open Presentation: Ctrl + O    - Opens an existing PowerPoint presentation from your computer. 3. Save Presentation: Ctrl + S    - Saves the current presentation to its existing file location. 4. Save As: F12    - Opens the "Save As" dialog box to save the current presentation with a new name or at a different location. 5. Close Presentation: Ctrl + W    - Closes the current presentation. 6. Cut: Ctrl + X    - Cuts the selected content (text, images, etc.) and places it on the clipboard for pasting. 7. Copy: Ctrl + C    - Copies the selected content (text, images, etc.) to the clipboard for duplication. 8. Paste: Ctrl + V    - Pastes the content from the clipboard into the presentation. 9. Undo: Ctrl + Z    - Reverses the last action perfor...

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 col...