diff --git a/_sidebar.md b/_sidebar.md new file mode 100644 index 0000000..783fbcb --- /dev/null +++ b/_sidebar.md @@ -0,0 +1,23 @@ +* [Home](README.md) +* [Declaration](declaration.md) +* [Learning Path](LEARNING-PATH.md) +* **Installation** + * [Installation](psql/installation.md) +* **Basics** + * [Data Types](psql/data-types.md) + * [Database](psql/database.md) + * [Functions](psql/functions.md) + * [Queries](psql/query.md) + * [Table & Schema](psql/table-schema.md) + * [Window Functions](psql/Window.md) +* **Advanced** + * [Clauses](psql/clauses.md) + * [CTE](psql/CTE.md) + * [Advance](psql/advance.md) +* **JSON / APIs** + * [JSON Guide](psql/json-jsonb-guide.md) + * [psql in ExpressJS](psql/psql-in-expressJS-guide.md) + * [my-sql-query](my-sql-query.md) + * [psql-query](psql-query.md) +* **Exercises** + * [Beginner Exercises](exercises/beginner-exercises.md) diff --git a/assets/custom.css b/assets/custom.css new file mode 100644 index 0000000..e5bf6c5 --- /dev/null +++ b/assets/custom.css @@ -0,0 +1,16 @@ +/* Example styling for branding */ +body::before { + content: "Learn PostgreSQL"; + display: block; + text-align: center; + font-size: 1.2rem; + font-weight: bold; + padding: 10px; + background-color: #3F51B5; + color: white; +} + +a[href$=".pdf"] { + color: #ff5722; + font-weight: bold; +} diff --git a/exercises/beginner-exercises.md b/exercises/beginner-exercises.md new file mode 100644 index 0000000..a9b1a91 --- /dev/null +++ b/exercises/beginner-exercises.md @@ -0,0 +1,278 @@ +# PostgreSQL Beginner Interview Questions and Answers + +This document contains a set of 30 beginner-friendly PostgreSQL questions along with detailed answers. These questions are suitable for interview preparation. + +--- + +## 1. What is PostgreSQL? +**Answer:** +PostgreSQL is an open-source, object-relational database management system (ORDBMS) that supports both SQL (relational) and JSON (non-relational) querying. It is highly extensible, reliable, and supports advanced data types. + +--- + +## 2. How do you create a new database in PostgreSQL? +**Answer:** +```sql +CREATE DATABASE my_database; +``` + +--- + +## 3. How do you list all databases in PostgreSQL? +**Answer:** +```sql +\l +-- or using SQL +SELECT datname FROM pg_database; +``` + +--- + +## 4. How do you connect to a specific database? +**Answer:** +```sql +\c my_database +``` + +--- + +## 5. How do you create a table in PostgreSQL? +**Answer:** +```sql +CREATE TABLE employees ( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, + age INT CHECK (age > 0), + department VARCHAR(50) +); +``` +- `SERIAL` automatically generates a unique number for `id`. +- `CHECK` enforces constraints on data integrity. + +--- + +## 6. How do you insert data into a table? +**Answer:** +```sql +INSERT INTO employees (name, age, department) +VALUES ('John Doe', 30, 'IT'); +``` + +--- + +## 7. How do you retrieve all data from a table? +**Answer:** +```sql +SELECT * FROM employees; +``` + +--- + +## 8. How do you retrieve specific columns from a table? +**Answer:** +```sql +SELECT name, department FROM employees; +``` + +--- + +## 9. How do you update data in a table? +**Answer:** +```sql +UPDATE employees +SET department = 'HR' +WHERE name = 'John Doe'; +``` +- `WHERE` clause ensures only the intended row(s) are updated. + +--- + +## 10. How do you delete data from a table? +**Answer:** +```sql +DELETE FROM employees +WHERE name = 'John Doe'; +``` + +--- + +## 11. How do you add a new column to an existing table? +**Answer:** +```sql +ALTER TABLE employees +ADD COLUMN salary NUMERIC(10,2); +``` +- `NUMERIC(10,2)` stores numbers with 10 digits total and 2 decimal places. + +--- + +## 12. How do you remove a column from a table? +**Answer:** +```sql +ALTER TABLE employees +DROP COLUMN salary; +``` + +--- + +## 13. How do you rename a column? +**Answer:** +```sql +ALTER TABLE employees +RENAME COLUMN department TO dept; +``` + +--- + +## 14. How do you rename a table? +**Answer:** +```sql +ALTER TABLE employees +RENAME TO staff; +``` + +--- + +## 15. How do you create an index on a column? +**Answer:** +```sql +CREATE INDEX idx_name ON employees(name); +``` +- Indexes improve query performance on frequently searched columns. + +--- + +## 16. What is the difference between `CHAR`, `VARCHAR`, and `TEXT`? +**Answer:** +- `CHAR(n)`: Fixed-length string, pads with spaces if less than n characters. +- `VARCHAR(n)`: Variable-length string with a maximum limit of n characters. +- `TEXT`: Variable-length string with no maximum limit. + +--- + +## 17. How do you find all employees older than 25? +**Answer:** +```sql +SELECT * FROM employees +WHERE age > 25; +``` + +--- + +## 18. How do you sort query results by a column in ascending order? +**Answer:** +```sql +SELECT * FROM employees +ORDER BY age ASC; +``` + +--- + +## 19. How do you sort query results in descending order? +**Answer:** +```sql +SELECT * FROM employees +ORDER BY age DESC; +``` + +--- + +## 20. How do you count the number of rows in a table? +**Answer:** +```sql +SELECT COUNT(*) FROM employees; +``` + +--- + +## 21. How do you find the maximum and minimum age? +**Answer:** +```sql +SELECT MAX(age) AS max_age, MIN(age) AS min_age +FROM employees; +``` + +--- + +## 22. How do you calculate the average age? +**Answer:** +```sql +SELECT AVG(age) AS average_age FROM employees; +``` + +--- + +## 23. How do you find unique departments? +**Answer:** +```sql +SELECT DISTINCT department FROM employees; +``` + +--- + +## 24. How do you filter records using multiple conditions? +**Answer:** +```sql +SELECT * FROM employees +WHERE age > 25 AND department = 'IT'; +``` + +--- + +## 25. How do you use the `LIKE` operator? +**Answer:** +```sql +SELECT * FROM employees +WHERE name LIKE 'J%'; -- Names starting with J +``` + +--- + +## 26. How do you use `IN` to filter specific values? +**Answer:** +```sql +SELECT * FROM employees +WHERE department IN ('IT', 'HR'); +``` + +--- + +## 27. How do you use `BETWEEN` to filter a range? +**Answer:** +```sql +SELECT * FROM employees +WHERE age BETWEEN 25 AND 35; +``` + +--- + +## 28. How do you join two tables? +**Answer:** +```sql +SELECT e.name, d.name AS dept_name +FROM employees e +JOIN departments d ON e.department_id = d.id; +``` +- `JOIN` combines rows from two tables based on a related column. + +--- + +## 29. How do you group data? +**Answer:** +```sql +SELECT department, COUNT(*) AS total_employees +FROM employees +GROUP BY department; +``` +- `GROUP BY` aggregates rows with the same column value. + +--- + +## 30. How do you delete a table? +**Answer:** +```sql +DROP TABLE employees; +``` + +--- + diff --git a/index.html b/index.html new file mode 100644 index 0000000..1d0860b --- /dev/null +++ b/index.html @@ -0,0 +1,32 @@ + + + + + + Learn PostgreSQL + + + + + +
+ + + + + + + + + + +