{"id":28798459,"url":"https://github.com/jahidul2004/explore-postgres","last_synced_at":"2026-02-26T04:51:38.613Z","repository":{"id":295420060,"uuid":"990058701","full_name":"jahidul2004/explore-postgres","owner":"jahidul2004","description":"A complete SQL practice guide with examples covering SELECT, UPDATE, DELETE, ALTER, aggregate functions, logical and date operations — all in one file for easy learning and copy-paste use.","archived":false,"fork":false,"pushed_at":"2025-05-26T08:15:55.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-25T11:44:57.843Z","etag":null,"topics":["database","ordbms","postgresql","rdbms","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jahidul2004.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-25T12:19:24.000Z","updated_at":"2025-05-26T08:17:01.000Z","dependencies_parsed_at":"2025-05-25T13:31:11.337Z","dependency_job_id":"ec82bfab-e776-4a9f-a693-9cb30804b251","html_url":"https://github.com/jahidul2004/explore-postgres","commit_stats":null,"previous_names":["jahidul2004/explore-postgres"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jahidul2004/explore-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jahidul2004%2Fexplore-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jahidul2004%2Fexplore-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jahidul2004%2Fexplore-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jahidul2004%2Fexplore-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jahidul2004","download_url":"https://codeload.github.com/jahidul2004/explore-postgres/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jahidul2004%2Fexplore-postgres/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29849041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T22:37:40.667Z","status":"online","status_checked_at":"2026-02-26T02:00:06.774Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","ordbms","postgresql","rdbms","sql"],"created_at":"2025-06-18T05:39:16.352Z","updated_at":"2026-02-26T04:51:38.607Z","avatar_url":"https://github.com/jahidul2004.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 🛢 PostgreSQL Practice Scripts – Complete Guide\n\nThis repository contains essential SQL practice examples covering various core topics such as `SELECT`, `UPDATE`, `DELETE`, logical operators, aggregate functions, and more. Each section below includes detailed explanations and real-world examples written for easy copy-paste and testing.\n\n---\n\n## 1. SELECT Statement\n\nThe `SELECT` statement is used to retrieve data from a table.\n\n```sql\n-- Select all columns from the employees table\nSELECT * FROM employees;\n\n-- Select specific columns\nSELECT name, department FROM employees;\n\n-- Select with alias\nSELECT name AS employee_name, salary AS monthly_salary FROM employees;\n```\n\n---\n\n## 2. UPDATE Statement\n\nThe `UPDATE` statement modifies existing records in a table.\n\n```sql\n-- Increase salary of employee with id 101\nUPDATE employees\nSET salary = 40000\nWHERE id = 101;\n\n-- Change department for all employees from 'Sales' to 'Marketing'\nUPDATE employees\nSET department = 'Marketing'\nWHERE department = 'Sales';\n```\n\n---\n\n## 3. DELETE Statement\n\nThe `DELETE` statement removes records from a table.\n\n```sql\n-- Delete a specific employee\nDELETE FROM employees\nWHERE id = 101;\n\n-- Delete all employees from 'Intern' department\nDELETE FROM employees\nWHERE department = 'Intern';\n\n-- Delete all records from a table (use with caution!)\nDELETE FROM employees;\n```\n\n---\n\n## 4. ALTER Statement\n\nThe `ALTER` statement is used to change the structure of a table.\n\n```sql\n-- Add a new column\nALTER TABLE employees\nADD birthdate DATE;\n\n-- Modify column data type\nALTER TABLE employees\nMODIFY name VARCHAR(100);\n\n-- Rename a column\nALTER TABLE employees\nRENAME COLUMN name TO full_name;\n\n-- Drop a column\nALTER TABLE employees\nDROP COLUMN birthdate;\n```\n\n---\n\n## 5. Aggregate Functions\n\nAggregate functions perform calculations on multiple rows.\n\n```sql\n-- Total salary of all employees\nSELECT SUM(salary) AS total_salary FROM employees;\n\n-- Average salary\nSELECT AVG(salary) AS average_salary FROM employees;\n\n-- Count total employees\nSELECT COUNT(*) AS total_employees FROM employees;\n\n-- Maximum salary\nSELECT MAX(salary) AS max_salary FROM employees;\n\n-- Minimum salary\nSELECT MIN(salary) AS min_salary FROM employees;\n```\n\n---\n\n## 6. Logical Operators (AND, OR, NOT)\n\nLogical operators combine multiple conditions in WHERE clauses.\n\n```sql\n-- Employees in 'HR' with salary \u003e 30000\nSELECT * FROM employees\nWHERE department = 'HR' AND salary \u003e 30000;\n\n-- Employees in 'IT' or 'Finance'\nSELECT * FROM employees\nWHERE department = 'IT' OR department = 'Finance';\n\n-- Employees not in 'Sales'\nSELECT * FROM employees\nWHERE NOT department = 'Sales';\n```\n\n---\n\n## 7. Date Functions\n\nDate functions are used to query based on date/time values.\n\n```sql\n-- Employees who joined in 2023\nSELECT * FROM employees\nWHERE YEAR(join_date) = 2023;\n\n-- Employees who joined in the last 30 days\nSELECT * FROM employees\nWHERE join_date \u003e= DATE_SUB(CURDATE(), INTERVAL 30 DAY);\n\n-- Current system date\nSELECT CURDATE();\n\n-- Current system timestamp\nSELECT NOW();\n```\n\n---\n\n## 8. LIMIT and OFFSET\n\nUsed to limit the number of rows returned.\n\n```sql\n-- Return the first 5 employees\nSELECT * FROM employees\nLIMIT 5;\n\n-- Skip the first 5 and return next 5\nSELECT * FROM employees\nLIMIT 5 OFFSET 5;\n\n-- Pagination example: Page 3 with 10 items per page\nSELECT * FROM employees\nORDER BY id\nLIMIT 10 OFFSET 20;\n```\n\n---\n\n## 9. IN, BETWEEN, LIKE Operators\n\nThese are used to filter data in more flexible ways.\n\n```sql\n-- Employees in specific departments\nSELECT * FROM employees\nWHERE department IN ('HR', 'IT', 'Finance');\n\n-- Employees with salary between 30000 and 50000\nSELECT * FROM employees\nWHERE salary BETWEEN 30000 AND 50000;\n\n-- Name starts with 'J'\nSELECT * FROM employees\nWHERE name LIKE 'J%';\n\n-- Name ends with 'son'\nSELECT * FROM employees\nWHERE name LIKE '%son';\n\n-- Name contains 'a'\nSELECT * FROM employees\nWHERE name LIKE '%a%';\n```\n\n---\n\n## 📌 Sample Table Schema\n\nAll examples above assume the existence of an `employees` table with the following schema:\n\n```sql\nCREATE TABLE employees (\n    id INT PRIMARY KEY,\n    name VARCHAR(100),\n    department VARCHAR(50),\n    salary DECIMAL(10, 2),\n    join_date DATE\n);\n```\n\n---\n\n## ⚠️ Important Notes\n\n- Always test `DELETE` and `UPDATE` queries in a safe environment before running on real data.\n- Use `SELECT` queries first to preview what will be affected.\n- This guide is ideal for beginners practicing SQL for job interviews, courses, or personal development.\n\n---\n\n## ✅ Author\n\nCreated by: **Jahidul Islam Jihad**  \nSQL Learning Repository for Beginners and Intermediate Users\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjahidul2004%2Fexplore-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjahidul2004%2Fexplore-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjahidul2004%2Fexplore-postgres/lists"}