Skip to main content

SQL Essentials - Mastering Databases and Data Queries

SQL Essentials - Mastering Databases and Data Queries

1. Introduction to SQL

SQL (Structured Query Language) is the standard language used to manage and manipulate relational databases such as MySQL, PostgreSQL, and SQL Server.

2. Setting Up Environment

  • Install MySQL or use SQLite for lightweight databases.
  • Use a client like phpMyAdmin or DBeaver to run SQL commands.

3. Basic SQL Commands

CREATE DATABASE company;
USE company;

CREATE TABLE employees (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(50),
  position VARCHAR(50),
  salary DECIMAL(10,2)
);

4. WHERE, ORDER BY, and LIMIT

SELECT * FROM employees WHERE salary > 50000;
SELECT * FROM employees ORDER BY name ASC;
SELECT * FROM employees LIMIT 5;

5. Joins

SELECT e.name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.id;

6. Aggregate Functions

SELECT COUNT(*) FROM employees;
SELECT AVG(salary) FROM employees;
SELECT MAX(salary) FROM employees;

7. CRUD Operations

-- Insert
INSERT INTO employees (name, position, salary)
VALUES ('Alice', 'Manager', 75000);

-- Read
SELECT * FROM employees;

-- Update
UPDATE employees SET salary = 80000 WHERE name = 'Alice';

-- Delete
DELETE FROM employees WHERE name = 'Alice';

8. Mini Project — Employee Database

Create a database named company and practice adding, updating, and deleting employee records. Use JOIN to connect multiple tables like departments and projects.

9. Conclusion

SQL is essential for anyone working with data. Mastering it allows you to query, manage, and analyze information efficiently — a must-have skill for developers and analysts alike.

Comments

Popular posts from this blog

How Android came into Existence

Android is a Linux Based Working Framework developed by GOOGLE which gives a rich application System and helps in creating intelligent applications. The first android operating system was released to the mobile market in 2007 with a considerable lot of its variants named in Sequential request going from A-N and impending is O.                                                               ANDROID VERSION HISTORY Alpha – The first primary adaptation of Android working Framework by Google. It has fundamental usefulness with a straightforward program and other Google applications like Gmail, Guides and YouTube.   Beta - Later on with Android 1.1 few greater usefulness added, the Programming interface changes from level 1 in Android 1.0 to level 2. It upholds connection with MMS (Multimedia Messages...