├── Giant Projects ├── Project 1 │ └── README.md ├── Project 2 │ └── README.md ├── Project 3 │ └── README.md ├── Project 4 │ └── README.md ├── Project 5 │ └── README.md └── README.md ├── LICENSE ├── README.md ├── SQL Fundamentals ├── 01 Data Query Language (DQL) │ ├── 01 SELECT Operations │ │ ├── 01 Select Statement │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Distinct │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Where Clause │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Like Operator │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 05 Wildcard Operator │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 06 In Operator │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 07 Between Operator │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 08 Is Null │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 09 And, Or, Not │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 Sorting and Limits │ │ ├── 01 Order By │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Limit │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Offset │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Top │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 03 Subqueries │ │ ├── 01 Single-Row Subqueries │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Multi-Row Subqueries │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Correlaed Subqueries │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Nested Subqueries │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 04 Conditional Logic │ │ ├── 01 Case Statements │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Coalesce │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Nullif │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ └── README.md ├── 02 Data Manipulation Language (DML) │ ├── 01 INSERT │ │ ├── 01 Single Row Insert │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Multiple Row Insert │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Insert from Select │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 UPDATE │ │ ├── 01 Single Column Update │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Multiple Column Update │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Update with Coditions │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 03 DELETE │ │ ├── 01 Delete with Conditions │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Delete All Rows │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ └── README.md ├── 03 Data Definition Language (DDL) │ ├── 01 Tables │ │ ├── 01 Create Table │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Alter Table │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Drop Table │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Truncate Table │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 Constraints │ │ ├── 01 Primary Key │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Foreign Key │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Unique │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Not Null │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 05 Check │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 06 Default │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 03 Views │ │ ├── 01 Create View │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Alter View │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Drop View │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ └── README.md ├── 04 Data Control Language (DCL) │ ├── 01 GRANT │ │ ├── 01 Grant Permissions │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Grant Roles │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 REVOKE │ │ ├── 01 Revoke Permissions │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Revoke Roles │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ └── README.md ├── 05 Transaction Control Language (TCL) │ ├── 01 COMMIT │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 ROLLBACK │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 03 SET TRANSACTION │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 04 SAVEPOINT │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── Interview Questions │ │ └── README.md │ └── README.md ├── 06 Joins and Aggregations │ ├── 01 Joins │ │ ├── 01 Inner Join │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Left Join │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Right Join │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Full Outer Join │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 05 Self-Join │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 06 Cross-Join │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 Aggregations │ │ ├── 01 Count │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Sum │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Avg │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Max │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 05 Min │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 06 Group By │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 07 Having Clause │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 03 Set Operations │ │ ├── 01 Union │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 02 Union All │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 03 Intersect │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── 04 Except │ │ │ ├── Learning │ │ │ │ └── README.md │ │ │ └── README.md │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ └── README.md ├── 07 Stored Procedures │ ├── 01 Creating Procedures │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 02 Parameters │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 03 Calling Procedures │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 04 Dropping Procedures │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── Interview Questions │ │ └── README.md │ ├── Projects │ │ └── README.md │ └── README.md ├── 08 Triggers │ ├── 01 Creating Triggers │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 02 BEFORE Triggers │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 03 AFTER Triggers │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 04 Dropping Triggers │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── Interview Questions │ │ └── README.md │ ├── Projects │ │ └── README.md │ └── README.md ├── 09 Cursors │ ├── 01 Declaring Cursors │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 02 Opening Cursors │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 03 Fetching Data │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 04 Closing Cursors │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── Interview Questions │ │ └── README.md │ ├── Projects │ │ └── README.md │ └── README.md ├── 10 Indexing │ ├── 01 Creating Indexes │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 02 B-Tree Indexes │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 03 Hash Indexes │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── 04 Specialty Indexes │ │ ├── Learning │ │ │ └── README.md │ │ └── README.md │ ├── Interview Questions │ │ └── README.md │ ├── Projects │ │ └── README.md │ └── README.md ├── 11 Extra Modules │ ├── 01 Pivot Queries │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 02 Dynamic Queries │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 03 User-Defined Functions │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 04 Window Functions │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 05 Common Table Expressions │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 06 Specialized Queries │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ ├── 07 DateTime Functions │ │ ├── Interview Questions │ │ │ └── README.md │ │ ├── Learning │ │ │ └── README.md │ │ ├── Projects │ │ │ └── README.md │ │ └── README.md │ └── README.md └── README.md ├── SQL Interview Questions with Ans └── README.md └── SQL Real World Case Studies ├── Interview Questions └── README.md └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 rohanmistry231 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/01 Select Statement/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master the SELECT Statement - Your SQL Starting Line! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **SELECT Statement** is the heart of SQL, letting you fetch data from tables like picking features for ML models. It’s your go-to for exploring datasets, pulling predictions, or prepping data for training. This guide will walk you through learning `SELECT` step-by-step, with ML-themed examples to make your *ML-Interview-Preparation-Hub* shine! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand the Basics**: Learn what `SELECT` does—grabs columns or all data from a table. 12 | 2. **Study the Syntax**: Memorize the core structure and try simple queries. 13 | 3. **Practice with Examples**: Run the examples below on a database like PostgreSQL or MySQL. 14 | 4. **Experiment**: Modify queries (e.g., change columns) to see how outputs change. 15 | 5. **Apply to ML**: Use `SELECT` to fetch data for a toy ML dataset (e.g., model scores). 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name; 23 | -- OR 24 | SELECT * FROM table_name; 25 | ``` 26 | 27 | - **Example 1: Basic SELECT**: 28 | ```sql 29 | SELECT model_id, score FROM predictions; 30 | ``` 31 | *Fetches `model_id` and `score` for all predictions, like grabbing features for ML analysis.* 32 | 33 | - **Example 2: Select All**: 34 | ```sql 35 | SELECT * FROM predictions; 36 | ``` 37 | *Pulls every column—great for exploring a dataset before training a model.* 38 | 39 | - **Example 3: Aliased Output**: 40 | ```sql 41 | SELECT model_id AS id, score AS model_score FROM predictions; 42 | ``` 43 | *Renames columns for clarity, useful in ML pipelines for readable outputs.* 44 | 45 | --- 46 | 47 | ## 💡 Practice Tips 48 | 49 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB (e.g., MySQL) to run queries. 50 | - **ML Use Case**: `SELECT` is key for pulling raw data (e.g., scores, features) for model training or evaluation. 51 | - **Try This**: Create a `predictions` table, insert 5 rows, and select `model_id` and `score`. Check if outputs match your data. 52 | - **Debug**: If no rows appear, ensure your table has data—use `SELECT COUNT(*) FROM predictions`. 53 | 54 | --- 55 | 56 | ## 🚀 Next Steps 57 | 58 | - **Deepen Your Skills**: Explore `DISTINCT` to remove duplicates or `WHERE` to filter data. 59 | - **Portfolio Boost**: Add your `SELECT` queries to `irohanportfolio.netlify.app`, explaining how they prep ML data. 60 | - **Challenge**: Write a `SELECT` query to fetch `model_name` and `score` for your portfolio’s ML dashboard. 61 | 62 | Happy querying, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/02 Distinct/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master DISTINCT - Clean Up Your ML Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **DISTINCT** keyword removes duplicate rows, ensuring your ML datasets are clean and unique. Think of it as deduplicating model IDs or feature categories before training. This guide will show you how to learn `DISTINCT` with ML-focused examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand `DISTINCT` eliminates duplicate rows or values. 12 | 2. **Learn the Syntax**: Study how `DISTINCT` fits into `SELECT`. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Play Around**: Change columns to see how duplicates vanish. 15 | 5. **ML Twist**: Use `DISTINCT` to prep unique data for model analysis. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT DISTINCT column1, column2, ... FROM table_name; 23 | -- OR 24 | SELECT DISTINCT ON (column) * FROM table_name; -- PostgreSQL-specific 25 | ``` 26 | 27 | - **Example 1: Unique Models**: 28 | ```sql 29 | SELECT DISTINCT model_id FROM predictions; 30 | ``` 31 | *Fetches unique `model_id`s, like getting a list of models for ML evaluation.* 32 | 33 | - **Example 2: Unique Combinations**: 34 | ```sql 35 | SELECT DISTINCT model_id, model_name FROM predictions; 36 | ``` 37 | *Removes duplicate pairs, ensuring clean model metadata for ML pipelines.* 38 | 39 | - **Example 3: PostgreSQL DISTINCT ON**: 40 | ```sql 41 | SELECT DISTINCT ON (model_id) model_id, score FROM predictions; 42 | ``` 43 | *Keeps the first `score` per `model_id`, useful for selecting top predictions.* 44 | 45 | --- 46 | 47 | ## 💡 Practice Tips 48 | 49 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or MySQL. 50 | - **ML Use Case**: `DISTINCT` helps create unique feature lists or model inventories for ML preprocessing. 51 | - **Try This**: Insert duplicate `model_id`s into `predictions`, then use `DISTINCT` to clean them. Verify with `SELECT COUNT(DISTINCT model_id)`. 52 | - **Watch Out**: `DISTINCT` on multiple columns deduplicates combinations—test single vs. multi-column queries. 53 | 54 | --- 55 | 56 | ## 🚀 Next Steps 57 | 58 | - **Level Up**: Pair `DISTINCT` with `WHERE` to filter unique rows or `ORDER BY` to sort them. 59 | - **Portfolio Win**: Add a `DISTINCT` query to `irohanportfolio.netlify.app`, showing how it cleans ML data. 60 | - **Challenge**: Fetch unique `model_name`s for a portfolio ML report. 61 | 62 | Keep those datasets clean, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/02 Distinct/README.md: -------------------------------------------------------------------------------- 1 | # 🎯 DISTINCT - Eliminating Duplicates in Query Results 2 | 3 | ## 🌟 Overview 4 | 5 | The **DISTINCT** keyword in SQL removes duplicate rows from the result set of a `SELECT` query, ensuring each row is unique based on the selected columns. It’s essential for summarizing data, identifying unique values, and cleaning datasets in AI/ML workflows. 6 | 7 | --- 8 | 9 | ## 📜 Syntax 10 | 11 | ```sql 12 | SELECT DISTINCT column1, column2, ... 13 | FROM table_name; 14 | ``` 15 | 16 | - **Single Column**: 17 | ```sql 18 | SELECT DISTINCT department 19 | FROM employees; 20 | ``` 21 | - **Multiple Columns**: 22 | ```sql 23 | SELECT DISTINCT city, state 24 | FROM customers; 25 | ``` 26 | 27 | --- 28 | 29 | ## 💡 Use Cases in AI/ML 30 | 31 | - **Data Cleaning**: Identify unique categories for feature encoding (e.g., `SELECT DISTINCT product_category FROM products`). 32 | - **Exploratory Analysis**: List unique user behaviors (e.g., `SELECT DISTINCT user_id FROM logins`). 33 | - **Deduplication**: Ensure no duplicate records in training data (e.g., `SELECT DISTINCT customer_id, purchase_date FROM orders`). 34 | - **Metadata Extraction**: Retrieve unique values for model metadata (e.g., `SELECT DISTINCT region FROM sales`). 35 | 36 | --- 37 | 38 | ## 🔑 Key Features 39 | 40 | - **Row-Level Uniqueness**: DISTINCT applies to the entire selected row, not individual columns. 41 | - **Multi-Column Support**: Uniqueness is based on the combination of all specified columns. 42 | - **NULL Handling**: NULL values are considered equal, so only one NULL appears in the result. 43 | 44 | --- 45 | 46 | ## ✅ Best Practices 47 | 48 | - **Use Sparingly**: DISTINCT can be resource-intensive on large datasets; consider alternatives like `GROUP BY` if possible. 49 | - **Select Specific Columns**: Only include columns necessary for uniqueness to minimize processing. 50 | - **Combine with ORDER BY**: Sort results for clarity (e.g., `SELECT DISTINCT department FROM employees ORDER BY department`). 51 | - **Test Performance**: Run `EXPLAIN` to check query cost, especially for large tables. 52 | 53 | --- 54 | 55 | ## ⚠️ Common Pitfalls 56 | 57 | - **Performance Overhead**: DISTINCT on large datasets or multiple columns can slow queries due to sorting or hashing. 58 | - **Unexpected Results**: When using multiple columns, uniqueness is based on the combination, not individual columns. 59 | - **NULL Confusion**: Be aware that NULLs are treated as identical, which may affect results. 60 | 61 | --- 62 | 63 | ## 📝 Additional Notes 64 | 65 | - **Database Variations**: Most databases (MySQL, PostgreSQL, SQL Server) support DISTINCT identically, but performance varies. 66 | - **DISTINCT ON**: PostgreSQL offers `DISTINCT ON` for selecting the first row of each group (not standard SQL). 67 | - **Alternatives**: For better performance, consider `GROUP BY` or indexing unique columns. -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/03 Where Clause/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master the WHERE Clause - Filter ML Data Like a Pro! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **WHERE Clause** filters rows based on conditions, letting you zoom in on specific ML data like high-scoring predictions or recent models. It’s your tool for slicing datasets before training or analysis. This guide will teach you `WHERE` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Purpose**: See how `WHERE` narrows down data with conditions. 12 | 2. **Memorize Syntax**: Learn the structure and basic operators (e.g., `=`, `>`). 13 | 3. **Try Examples**: Run the queries below in a database like MySQL. 14 | 4. **Tweak Queries**: Adjust conditions to explore different filters. 15 | 5. **ML Angle**: Use `WHERE` to prep data for ML feature selection. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name WHERE condition; 23 | ``` 24 | 25 | - **Example 1: High Scores**: 26 | ```sql 27 | SELECT prediction_id, score FROM predictions WHERE score > 0.9; 28 | ``` 29 | *Fetches predictions with `score > 0.9`, like selecting top performers for ML evaluation.* 30 | 31 | - **Example 2: Specific Model**: 32 | ```sql 33 | SELECT model_id, model_name FROM predictions WHERE model_id = 101; 34 | ``` 35 | *Filters for `model_id = 101`, great for isolating a model’s data.* 36 | 37 | - **Example 3: Date Filter**: 38 | ```sql 39 | SELECT * FROM predictions WHERE prediction_date = '2025-01-01'; 40 | ``` 41 | *Grabs predictions for a specific date, useful for time-based ML analysis.* 42 | 43 | --- 44 | 45 | ## 💡 Practice Tips 46 | 47 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL to test filters. 48 | - **ML Use Case**: `WHERE` is crucial for filtering features or predictions (e.g., high-confidence scores) for ML models. 49 | - **Try This**: Create a `predictions` table, add 10 rows, and filter `score > 0.8`. Check row counts with `SELECT COUNT(*)`. 50 | - **Debug Tip**: If no results show, verify your condition (e.g., correct column name, data exists). 51 | 52 | --- 53 | 54 | ## 🚀 Next Steps 55 | 56 | - **Go Deeper**: Combine `WHERE` with `AND, OR, NOT` for complex filters or `LIKE` for text matching. 57 | - **Portfolio Boost**: Add a `WHERE` query to `irohanportfolio.netlify.app`, explaining its ML data prep role. 58 | - **Challenge**: Filter `score > 0.85` for a portfolio ML feature report. 59 | 60 | Filter like a champ, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/04 Like Operator/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master the LIKE Operator - Hunt for ML Text Patterns! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **LIKE Operator** searches for patterns in text, perfect for finding model names or categories in ML datasets. Paired with wildcards, it’s your go-to for fuzzy matching in data exploration. This guide will show you how to learn `LIKE` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Know the Goal**: Understand `LIKE` finds text matching a pattern. 12 | 2. **Learn Syntax**: Study `LIKE` with `%` and `_` wildcards. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Mix It Up**: Change patterns to test different matches. 15 | 5. **ML Spin**: Use `LIKE` to filter text data for ML preprocessing. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name WHERE column LIKE pattern; 23 | ``` 24 | 25 | - **Example 1: Model Name Search**: 26 | ```sql 27 | SELECT model_id, model_name FROM predictions WHERE model_name LIKE 'Neural%'; 28 | ``` 29 | *Finds models starting with 'Neural', like filtering neural nets for ML analysis.* 30 | 31 | - **Example 2: Partial Match**: 32 | ```sql 33 | SELECT * FROM predictions WHERE model_name LIKE '%Boost%'; 34 | ``` 35 | *Matches 'Boost' anywhere, great for finding boosting models like XGBoost.* 36 | 37 | - **Example 3: Single Character**: 38 | ```sql 39 | SELECT model_name FROM predictions WHERE model_name LIKE 'X_Boost'; 40 | ``` 41 | *Matches 'X_Boost' with one character (e.g., 'XGBoost'), useful for precise ML tags.* 42 | 43 | --- 44 | 45 | ## 💡 Practice Tips 46 | 47 | - **Tool Up**: Test on [DB Fiddle](https://www.db-fiddle.com) or MySQL. 48 | - **ML Use Case**: `LIKE` helps filter text-based features (e.g., model types, labels) for ML pipelines. 49 | - **Try This**: Add `model_name`s like 'NeuralNet', 'XGBoost' to `predictions`, then use `LIKE '%Net%'`. Count matches. 50 | - **Note**: `LIKE` is case-sensitive in some DBs (e.g., PostgreSQL)—use `ILIKE` for case-insensitive matches. 51 | 52 | --- 53 | 54 | ## 🚀 Next Steps 55 | 56 | - **Expand Skills**: Pair `LIKE` with `Wildcard Operator` for advanced patterns or `WHERE` for combined filters. 57 | - **Portfolio Win**: Add a `LIKE` query to `irohanportfolio.netlify.app`, showing text filtering for ML. 58 | - **Challenge**: Find models with 'Net' in `model_name` for a portfolio ML report. 59 | 60 | Search like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/05 Wildcard Operator/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master the Wildcard Operator - Unlock Flexible ML Filters! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Wildcard Operators** (`%` and `_`) supercharge `LIKE`, letting you match flexible text patterns in ML data, like model names or feature tags. They’re key for exploring datasets with partial info. This guide will teach you wildcards with ML examples, making your *ML-Interview-Preparation-Hub* shine! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Wildcards**: Learn `%` (any characters) vs. `_` (one character). 12 | 2. **Study Syntax**: See how wildcards work with `LIKE`. 13 | 3. **Try Examples**: Run the queries below in a database like MySQL. 14 | 4. **Experiment**: Test different patterns to master matching. 15 | 5. **ML Angle**: Use wildcards to filter text for ML feature prep. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name WHERE column LIKE pattern; 23 | -- %: Any number of characters 24 | -- _: Exactly one character 25 | ``` 26 | 27 | - **Example 1: Broad Match**: 28 | ```sql 29 | SELECT model_name FROM predictions WHERE model_name LIKE 'N%'; 30 | ``` 31 | *Matches names starting with 'N' (e.g., 'NeuralNet'), like filtering ML model types.* 32 | 33 | - **Example 2: Specific Position**: 34 | ```sql 35 | SELECT * FROM predictions WHERE model_name LIKE '_GBoost'; 36 | ``` 37 | *Matches 'XGBoost' with one character before 'GBoost', great for precise ML tags.* 38 | 39 | - **Example 3: Middle Match**: 40 | ```sql 41 | SELECT model_id, model_name FROM predictions WHERE model_name LIKE '%Net%'; 42 | ``` 43 | *Finds 'Net' anywhere, useful for grabbing neural network models.* 44 | 45 | --- 46 | 47 | ## 💡 Practice Tips 48 | 49 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL. 50 | - **ML Use Case**: Wildcards help filter text features (e.g., model categories) for ML datasets. 51 | - **Try This**: Add `model_name`s like 'NeuralNet', 'XGBoost', then try `LIKE 'X%ost'`. Check results. 52 | - **Tip**: Combine `%` and `_` for complex patterns, but keep patterns specific to avoid over-matching. 53 | 54 | --- 55 | 56 | ## 🚀 Next Steps 57 | 58 | - **Go Further**: Use wildcards with `LIKE Operator` or `AND, OR, NOT` for advanced filters. 59 | - **Portfolio Boost**: Add a wildcard query to `irohanportfolio.netlify.app`, explaining its ML role. 60 | - **Challenge**: Match models ending in 'Boost' for a portfolio ML feature list. 61 | 62 | Pattern-match like a boss, and let’s make your SQL skills pop! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/06 In Operator/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master the IN Operator - Pick Your ML Data Easily! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **IN Operator** lets you filter rows matching a list of values, like selecting specific models or scores for ML analysis. It’s a clean way to grab exactly what you need from datasets. This guide will walk you through learning `IN` with ML examples, powering your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: See how `IN` checks if a column matches any value in a list. 12 | 2. **Learn Syntax**: Study `IN` with simple value lists. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Play with Lists**: Add or remove values to see the effect. 15 | 5. **ML Spin**: Use `IN` to select specific ML model data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name WHERE column IN (value1, value2, ...); 23 | ``` 24 | 25 | - **Example 1: Select Models**: 26 | ```sql 27 | SELECT model_id, model_name FROM predictions WHERE model_id IN (101, 102); 28 | ``` 29 | *Fetches data for `model_id` 101 and 102, like picking models for ML comparison.* 30 | 31 | - **Example 2: Name Filter**: 32 | ```sql 33 | SELECT * FROM predictions WHERE model_name IN ('NeuralNet', 'XGBoost'); 34 | ``` 35 | *Grabs rows for specific model names, great for ML pipeline filtering.* 36 | 37 | - **Example 3: Subquery IN**: 38 | ```sql 39 | SELECT prediction_id, score FROM predictions 40 | WHERE model_id IN (SELECT model_id FROM predictions WHERE score > 0.9); 41 | ``` 42 | *Filters based on high-scoring models, useful for dynamic ML data prep.* 43 | 44 | --- 45 | 46 | ## 💡 Practice Tips 47 | 48 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or MySQL. 49 | - **ML Use Case**: `IN` simplifies selecting model IDs or categories for ML feature engineering. 50 | - **Try This**: Add 5 `model_id`s to `predictions`, then use `IN (101, 103)`. Verify with `SELECT COUNT(*)`. 51 | - **Note**: `IN` is faster than multiple `OR` conditions—test both to compare. 52 | 53 | --- 54 | 55 | ## 🚀 Next Steps 56 | 57 | - **Level Up**: Combine `IN` with `WHERE` or `AND, OR, NOT` for complex filters. 58 | - **Portfolio Win**: Add an `IN` query to `irohanportfolio.netlify.app`, showing ML data selection. 59 | - **Challenge**: Use `IN` to pick 3 `model_name`s for a portfolio ML report. 60 | 61 | Select with ease, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/07 Between Operator/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master the BETWEEN Operator - Range Your ML Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **BETWEEN Operator** filters rows within a range, like grabbing predictions from a date range or scores for ML analysis. It’s perfect for zooming in on continuous data like timestamps or metrics. This guide will teach you `BETWEEN` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Ranges**: Learn how `BETWEEN` selects values inclusively. 12 | 2. **Study Syntax**: See `BETWEEN` with numbers, dates, or text. 13 | 3. **Try Examples**: Run the queries below in a database like MySQL. 14 | 4. **Adjust Ranges**: Test different bounds to explore outputs. 15 | 5. **ML Twist**: Use `BETWEEN` to slice data for ML model evaluation. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name WHERE column BETWEEN value1 AND value2; 23 | ``` 24 | 25 | - **Example 1: Score Range**: 26 | ```sql 27 | SELECT prediction_id, score FROM predictions WHERE score BETWEEN 0.8 AND 0.9; 28 | ``` 29 | *Fetches predictions with scores from 0.8 to 0.9, like selecting mid-range ML outputs.* 30 | 31 | - **Example 2: Date Range**: 32 | ```sql 33 | SELECT * FROM predictions WHERE prediction_date BETWEEN '2025-01-01' AND '2025-01-31'; 34 | ``` 35 | *Grabs January 2025 predictions, great for time-based ML analysis.* 36 | 37 | - **Example 3: Combined Filter**: 38 | ```sql 39 | SELECT model_id, score FROM predictions 40 | WHERE score BETWEEN 0.7 AND 0.95 AND model_id = 101; 41 | ``` 42 | *Filters scores for a specific model, useful for targeted ML data prep.* 43 | 44 | --- 45 | 46 | ## 💡 Practice Tips 47 | 48 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL. 49 | - **ML Use Case**: `BETWEEN` helps select feature ranges (e.g., scores, dates) for ML datasets. 50 | - **Try This**: Add predictions with `score` from 0.6 to 1.0, then use `BETWEEN 0.85 AND 0.95`. Count rows. 51 | - **Tip**: `BETWEEN` is inclusive—test edge cases (e.g., exact bounds) to confirm behavior. 52 | 53 | --- 54 | 55 | ## 🚀 Next Steps 56 | 57 | - **Go Deeper**: Pair `BETWEEN` with `AND, OR, NOT` or `WHERE` for complex ranges. 58 | - **Portfolio Boost**: Add a `BETWEEN` query to `irohanportfolio.netlify.app`, explaining ML data slicing. 59 | - **Challenge**: Filter scores between 0.9 and 1.0 for a portfolio ML report. 60 | 61 | Range like a pro, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/08 Is Null/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master IS NULL - Handle Missing ML Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **IS NULL** operator finds rows with missing values, crucial for cleaning ML datasets before training. Whether it’s absent scores or undefined model names, `IS NULL` helps you spot gaps. This guide will show you how to learn `IS NULL` with ML examples, powering your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Know the Deal**: Understand `IS NULL` checks for missing data. 12 | 2. **Learn Syntax**: Study `IS NULL` and `IS NOT NULL`. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Test Scenarios**: Add nulls to data and query them. 15 | 5. **ML Angle**: Use `IS NULL` to clean datasets for ML pipelines. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name WHERE column IS NULL; 23 | -- OR 24 | SELECT column1, column2, ... FROM table_name WHERE column IS NOT NULL; 25 | ``` 26 | 27 | - **Example 1: Missing Names**: 28 | ```sql 29 | SELECT prediction_id, model_id FROM predictions WHERE model_name IS NULL; 30 | ``` 31 | *Finds rows with no `model_name`, like spotting incomplete ML metadata.* 32 | 33 | - **Example 2: Non-Null Scores**: 34 | ```sql 35 | SELECT * FROM predictions WHERE score IS NOT NULL; 36 | ``` 37 | *Grabs predictions with valid `score`s, great for ML model training.* 38 | 39 | - **Example 3: Combined Check**: 40 | ```sql 41 | SELECT model_id, score FROM predictions 42 | WHERE model_name IS NULL AND score IS NOT NULL; 43 | ``` 44 | *Filters for missing names but valid scores, useful for ML data quality checks.* 45 | 46 | --- 47 | 48 | ## 💡 Practice Tips 49 | 50 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or MySQL. 51 | - **ML Use Case**: `IS NULL` helps identify missing features or labels for ML preprocessing. 52 | - **Try This**: Insert 5 rows with some `model_name` as `NULL`, then use `IS NULL`. Verify with `SELECT COUNT(*)`. 53 | - **Watch Out**: Don’t use `= NULL`—it fails! Always use `IS NULL`. 54 | 55 | --- 56 | 57 | ## 🚀 Next Steps 58 | 59 | - **Level Up**: Combine `IS NULL` with `WHERE` or `AND, OR, NOT` for advanced cleaning. 60 | - **Portfolio Win**: Add an `IS NULL` query to `irohanportfolio.netlify.app`, showing ML data cleanup. 61 | - **Challenge**: Find `NULL` `score`s for a portfolio ML quality report. 62 | 63 | Clean data like a champ, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/08 Is Null/README.md: -------------------------------------------------------------------------------- 1 | # 🕳️ IS NULL - Handling Missing Data 2 | 3 | ## 🌟 Overview 4 | 5 | The **IS NULL** condition in a `WHERE` clause filters rows where a column contains a `NULL` value, while `IS NOT NULL` selects non-NULL values. It’s crucial for data cleaning and validation in AI/ML, where missing data can skew model performance. 6 | 7 | --- 8 | 9 | ## 📜 Syntax 10 | 11 | ```sql 12 | SELECT column1, column2, ... 13 | FROM table_name 14 | WHERE column IS NULL; 15 | ``` 16 | 17 | - **IS NULL Example**: 18 | ```sql 19 | SELECT customer_id 20 | FROM customers 21 | WHERE email IS NULL; 22 | ``` 23 | - **IS NOT NULL Example**: 24 | ```sql 25 | SELECT order_id 26 | FROM orders 27 | WHERE delivery_date IS NOT NULL; 28 | ``` 29 | 30 | --- 31 | 32 | ## 💡 Use Cases in AI/ML 33 | 34 | - **Data Cleaning**: Identify missing values for imputation (e.g., `SELECT * FROM profiles WHERE age IS NULL`). 35 | - **Quality Checks**: Ensure critical fields are populated (e.g., `SELECT * FROM transactions WHERE amount IS NOT NULL`). 36 | - **Feature Validation**: Exclude incomplete records (e.g., `SELECT user_id FROM logins WHERE session_id IS NOT NULL`). 37 | - **Missing Data Analysis**: Quantify NULLs in datasets (e.g., `SELECT COUNT(*) FROM employees WHERE manager_id IS NULL`). 38 | 39 | --- 40 | 41 | ## 🔑 Key Features 42 | 43 | - **NULL-Specific**: Unlike `= NULL`, which fails, `IS NULL` correctly identifies NULL values. 44 | - **Boolean Logic**: Returns true/false based on the presence of NULL. 45 | - **Universal**: Works with any data type (numbers, strings, dates). 46 | 47 | --- 48 | 49 | ## ✅ Best Practices 50 | 51 | - **Use IS NULL Explicitly**: Never use `= NULL` or `!= NULL`, as they don’t work as expected. 52 | - **Combine with Other Filters**: Narrow results for efficiency (e.g., `WHERE department = 'HR' AND manager_id IS NULL`). 53 | - **Check Indexes**: Filtering on NULLs may not use indexes unless explicitly designed (e.g., partial indexes in PostgreSQL). 54 | - **Document NULLs**: Understand why NULLs exist in your data to avoid misinterpretation. 55 | 56 | --- 57 | 58 | ## ⚠️ Common Pitfalls 59 | 60 | - **Misusing Equality**: Writing `WHERE column = NULL` instead of `IS NULL` returns no rows. 61 | - **Assuming Non-NULL**: Forgetting to check for NULLs can include invalid data in ML models. 62 | - **Performance**: Filtering NULLs on unindexed columns can be slow in large datasets. 63 | - **Logical Errors**: NULLs affect `AND`/`OR` logic differently (e.g., `NULL AND TRUE` is NULL). 64 | 65 | --- 66 | 67 | ## 📝 Additional Notes 68 | 69 | - **Database Variations**: IS NULL is standard across MySQL, PostgreSQL, and SQL Server. 70 | - **NULL Semantics**: NULL represents unknown or missing data, not zero or an empty string. 71 | - **Alternatives**: For handling NULLs in calculations, consider `COALESCE` (covered in Conditional Logic). -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/01 SELECT Operations/09 And, Or, Not/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master AND, OR, NOT - Combine ML Filters with Ease! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **AND, OR, NOT** operators combine conditions in `WHERE`, letting you craft precise ML data filters like high scores from specific models. They’re your tools for building complex queries fast. This guide will teach you `AND, OR, NOT` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Logic**: Understand `AND` (all true), `OR` (any true), `NOT` (exclude). 12 | 2. **Study Syntax**: Learn how they fit into `WHERE`. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Mix Conditions**: Combine operators to test different filters. 15 | 5. **ML Spin**: Use `AND, OR, NOT` to refine ML datasets. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name 23 | WHERE condition1 AND condition2; 24 | -- OR 25 | WHERE condition1 OR condition2; 26 | -- OR 27 | WHERE NOT condition; 28 | ``` 29 | 30 | - **Example 1: AND Filter**: 31 | ```sql 32 | SELECT prediction_id, score FROM predictions 33 | WHERE model_id = 101 AND score > 0.9; 34 | ``` 35 | *Fetches high scores for `model_id = 101`, like selecting top ML predictions.* 36 | 37 | - **Example 2: OR Filter**: 38 | ```sql 39 | SELECT * FROM predictions 40 | WHERE model_name = 'NeuralNet' OR model_name = 'XGBoost'; 41 | ``` 42 | *Grabs rows for either model, great for comparing ML models.* 43 | 44 | - **Example 3: NOT Filter**: 45 | ```sql 46 | SELECT model_id, model_name FROM predictions 47 | WHERE NOT model_name = 'NeuralNet'; 48 | ``` 49 | *Excludes 'NeuralNet', useful for filtering out specific ML categories.* 50 | 51 | --- 52 | 53 | ## 💡 Practice Tips 54 | 55 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL. 56 | - **ML Use Case**: `AND, OR, NOT` help build precise feature filters for ML pipelines. 57 | - **Try This**: Add 10 rows to `predictions`, then use `model_id = 102 AND score < 0.8`. Check results. 58 | - **Tip**: Use parentheses with multiple operators (e.g., `(A AND B) OR C`) to control logic. 59 | 60 | --- 61 | 62 | ## 🚀 Next Steps 63 | 64 | - **Go Further**: Pair `AND, OR, NOT` with `WHERE`, `IN`, or `BETWEEN` for complex queries. 65 | - **Portfolio Boost**: Add an `AND, OR, NOT` query to `irohanportfolio.netlify.app`, explaining ML filtering. 66 | - **Challenge**: Combine `AND` and `OR` to filter scores and models for a portfolio ML report. 67 | 68 | Combine like a pro, and let’s make your SQL skills shine! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/02 Sorting and Limits/01 Order By/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master ORDER BY - Sort Your ML Data Like a Pro! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **ORDER BY** clause sorts your SQL results, perfect for ranking ML predictions or organizing features by date. It’s your go-to for making data readable and analysis-ready. This guide will walk you through learning `ORDER BY` with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `ORDER BY` sorts rows by columns. 12 | 2. **Study the Syntax**: Learn `ASC` (ascending) and `DESC` (descending). 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL or MySQL. 14 | 4. **Experiment**: Change sort columns or directions to see the impact. 15 | 5. **Apply to ML**: Use `ORDER BY` to rank model scores or sort datasets for ML pipelines. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name 23 | ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...; 24 | ``` 25 | 26 | - **Example 1: Sort by Score**: 27 | ```sql 28 | SELECT prediction_id, score FROM predictions 29 | ORDER BY score DESC; 30 | ``` 31 | *Sorts predictions by `score` from highest to lowest, like ranking ML model outputs.* 32 | 33 | - **Example 2: Multi-Column Sort**: 34 | ```sql 35 | SELECT model_id, score, prediction_date FROM predictions 36 | ORDER BY model_id ASC, score DESC; 37 | ``` 38 | *Sorts by `model_id` (ascending), then `score` (descending), great for organizing ML results.* 39 | 40 | - **Example 3: Sort by Name**: 41 | ```sql 42 | SELECT model_name, model_id FROM predictions 43 | ORDER BY model_name ASC; 44 | ``` 45 | *Orders by `model_name` alphabetically, useful for ML model cataloging.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test sorting. 52 | - **ML Use Case**: `ORDER BY` is key for ranking predictions (e.g., top scores) or sorting time-series data for ML models. 53 | - **Try This**: Create a `predictions` table with 10 rows, then sort by `score DESC`. Verify the highest score is first. 54 | - **Debug**: If sorting seems off, check data types (e.g., `VARCHAR` sorts differently than `FLOAT`). 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Deepen Skills**: Pair `ORDER BY` with `LIMIT` to grab top rows or `WHERE` to sort filtered data. 61 | - **Portfolio Boost**: Add an `ORDER BY` query to `irohanportfolio.netlify.app`, explaining how it ranks ML data. 62 | - **Challenge**: Sort `score` and `model_name` for a portfolio ML leaderboard. 63 | 64 | Sort like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/02 Sorting and Limits/02 Limit/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master LIMIT - Sample Your ML Data with Ease! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **LIMIT** clause caps the number of rows returned, ideal for sampling ML datasets or grabbing top predictions. It’s your tool for quick data previews without overwhelming outputs. This guide will show you how to learn `LIMIT` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: See how `LIMIT` restricts row counts. 12 | 2. **Learn Syntax**: Study `LIMIT` and its DB variations (e.g., `TOP` in SQL Server). 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Tweak Limits**: Adjust row counts to explore results. 15 | 5. **ML Spin**: Use `LIMIT` to sample data for ML model testing. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name 23 | LIMIT number; 24 | -- MySQL/PostgreSQL syntax 25 | ``` 26 | 27 | - **Example 1: Top 5 Scores**: 28 | ```sql 29 | SELECT prediction_id, score FROM predictions 30 | ORDER BY score DESC 31 | LIMIT 5; 32 | ``` 33 | *Grabs the top 5 highest `score`s, like sampling top ML predictions.* 34 | 35 | - **Example 2: Sample Models**: 36 | ```sql 37 | SELECT model_id, model_name FROM predictions 38 | LIMIT 3; 39 | ``` 40 | *Returns 3 rows, great for quick ML dataset previews.* 41 | 42 | - **Example 3: SQL Server TOP**: 43 | ```sql 44 | SELECT TOP 4 model_id, score FROM predictions 45 | ORDER BY score DESC; 46 | ``` 47 | *SQL Server’s `TOP` equivalent, useful for cross-DB ML pipelines.* 48 | 49 | --- 50 | 51 | ## 💡 Practice Tips 52 | 53 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or MySQL. 54 | - **ML Use Case**: `LIMIT` helps sample small datasets for ML prototyping or grab top results for analysis. 55 | - **Try This**: Add 20 rows to `predictions`, then use `LIMIT 10`. Count rows with `SELECT COUNT(*)`. 56 | - **Note**: Always pair `LIMIT` with `ORDER BY` for predictable results—unsorted `LIMIT` is random! 57 | 58 | --- 59 | 60 | ## 🚀 Next Steps 61 | 62 | - **Level Up**: Combine `LIMIT` with `OFFSET` for pagination or `ORDER BY` for ranked sampling. 63 | - **Portfolio Win**: Add a `LIMIT` query to `irohanportfolio.netlify.app`, showing ML data sampling. 64 | - **Challenge**: Use `LIMIT` to grab 5 top `score`s for a portfolio ML report. 65 | 66 | Sample smart, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/02 Sorting and Limits/03 Offset/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master OFFSET - Paginate Your ML Data Like a Boss! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **OFFSET** clause skips rows before returning results, perfect for paginating ML datasets or skipping early predictions. Paired with `LIMIT`, it’s your key to navigating big data. This guide will teach you `OFFSET` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Skipping**: Learn how `OFFSET` jumps over rows. 12 | 2. **Study Syntax**: See `OFFSET` with `LIMIT` and `ORDER BY`. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Play with Skips**: Adjust `OFFSET` values to explore pages. 15 | 5. **ML Angle**: Use `OFFSET` to paginate ML results for dashboards. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... FROM table_name 23 | ORDER BY column 24 | LIMIT number OFFSET number; 25 | -- PostgreSQL/MySQL syntax 26 | ``` 27 | 28 | - **Example 1: Second Page of Scores**: 29 | ```sql 30 | SELECT prediction_id, score FROM predictions 31 | ORDER BY score DESC 32 | LIMIT 5 OFFSET 5; 33 | ``` 34 | *Skips the top 5 scores, grabs the next 5, like paginating ML leaderboards.* 35 | 36 | - **Example 2: Skip Early Predictions**: 37 | ```sql 38 | SELECT model_id, prediction_date FROM predictions 39 | ORDER BY prediction_date ASC 40 | LIMIT 3 OFFSET 10; 41 | ``` 42 | *Skips the first 10 rows, great for ML time-series analysis.* 43 | 44 | - **Example 3: Paginate Models**: 45 | ```sql 46 | SELECT model_name, score FROM predictions 47 | ORDER BY model_name ASC 48 | LIMIT 4 OFFSET 4; 49 | ``` 50 | *Gets the second page of models, useful for ML catalog browsing.* 51 | 52 | --- 53 | 54 | ## 💡 Practice Tips 55 | 56 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 57 | - **ML Use Case**: `OFFSET` enables paginated dashboards or batch processing for ML datasets. 58 | - **Try This**: Insert 15 rows into `predictions`, then use `LIMIT 5 OFFSET 5`. Verify rows 6-10 appear. 59 | - **Tip**: Always use `ORDER BY` with `OFFSET`—skipping unsorted rows is unpredictable. 60 | 61 | --- 62 | 63 | ## 🚀 Next Steps 64 | 65 | - **Go Deeper**: Pair `OFFSET` with `LIMIT` for full pagination or `WHERE` for filtered pages. 66 | - **Portfolio Boost**: Add an `OFFSET` query to `irohanportfolio.netlify.app`, explaining ML pagination. 67 | - **Challenge**: Paginate `score`s (5 per page) for a portfolio ML dashboard. 68 | 69 | Page like a pro, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/02 Sorting and Limits/04 Top/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master TOP - Grab the Best ML Data Fast! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **TOP** clause (SQL Server’s answer to `LIMIT`) fetches a fixed number of rows, perfect for snagging top ML predictions or sampling datasets. It’s your shortcut to quick, ranked results. This guide will show you how to learn `TOP` with ML examples, powering your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand `TOP` pulls a set number of rows. 12 | 2. **Learn Syntax**: Study `TOP` with and without `WITH TIES`. 13 | 3. **Run Examples**: Try the queries below in SQL Server. 14 | 4. **Test Limits**: Adjust `TOP` counts to see changes. 15 | 5. **ML Spin**: Use `TOP` to sample or rank ML data for analysis. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT TOP number [WITH TIES] column1, column2, ... FROM table_name 23 | ORDER BY column; 24 | -- SQL Server syntax 25 | ``` 26 | 27 | - **Example 1: Top 5 Scores**: 28 | 29 | ```sql 30 | SELECT TOP 5 prediction_id, score FROM predictions 31 | ORDER BY score DESC; 32 | ``` 33 | 34 | *Grabs the 5 highest* `score`*s, like picking top ML predictions.* 35 | 36 | - **Example 2: Top with Ties**: 37 | 38 | ```sql 39 | SELECT TOP 3 WITH TIES model_id, score FROM predictions 40 | ORDER BY score DESC; 41 | ``` 42 | 43 | *Fetches the top 3* `score`*s, including ties, great for fair ML rankings.* 44 | 45 | - **Example 3: Top Models**: 46 | 47 | ```sql 48 | SELECT TOP 4 model_name, model_id FROM predictions 49 | ORDER BY model_name ASC; 50 | ``` 51 | 52 | *Gets the first 4 models alphabetically, useful for ML catalog previews.* 53 | 54 | --- 55 | 56 | ## 💡 Practice Tips 57 | 58 | - **Tool Up**: Practice in SQL Server or DB Fiddle. 59 | - **ML Use Case**: `TOP` is ideal for sampling datasets or ranking predictions for ML evaluation. 60 | - **Try This**: Add 10 rows to `predictions`, then use `TOP 3 WITH TIES` on `score DESC`. Check for tied scores. 61 | - **Note**: `TOP` needs `ORDER BY` for meaningful results—unsorted `TOP` is random. 62 | 63 | --- 64 | 65 | ## 🚀 Next Steps 66 | 67 | - **Level Up**: Combine `TOP` with `WHERE` for filtered rankings or `ORDER BY` for custom sorts. 68 | - **Portfolio Win**: Add a `TOP` query to `irohanportfolio.netlify.app`, showing ML data ranking. 69 | - **Challenge**: Use `TOP 5` to grab highest `score`s for a portfolio ML leaderboard. 70 | 71 | Rank like a boss, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/04 Conditional Logic/02 Coalesce/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master COALESCE - Clean Your ML Data with Ease! 2 | 3 | ## 🌟 Welcome 4 | 5 | **COALESCE** picks the first non-null value from a list, ideal for filling gaps in ML datasets like missing model names or scores. It’s your tool for ensuring clean, usable data. This guide will show you how to learn `COALESCE` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: See how `COALESCE` handles nulls by selecting the first non-null. 12 | 2. **Learn Syntax**: Study `COALESCE` with multiple arguments. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Nulls**: Add nulls to data and apply `COALESCE`. 15 | 5. **ML Spin**: Use `COALESCE` to prep clean data for ML pipelines. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT COALESCE(column1, column2, ..., default_value) AS alias 23 | FROM table_name; 24 | ``` 25 | 26 | - **Example 1: Default Model Name**: 27 | ```sql 28 | SELECT prediction_id, 29 | COALESCE(model_name, 'Unknown') AS model_name 30 | FROM predictions; 31 | ``` 32 | *Replaces null `model_name`s with 'Unknown', like cleaning ML metadata.* 33 | 34 | - **Example 2: Fallback Score**: 35 | ```sql 36 | SELECT prediction_id, model_id, 37 | COALESCE(score, 0.0) AS cleaned_score 38 | FROM predictions; 39 | ``` 40 | *Sets null `score`s to 0.0, great for ML model evaluation.* 41 | 42 | - **Example 3: Multiple Columns**: 43 | ```sql 44 | SELECT prediction_id, 45 | COALESCE(model_name, (SELECT model_name FROM models WHERE models.model_id = predictions.model_id), 'Generic') AS final_name 46 | FROM predictions; 47 | ``` 48 | *Tries `model_name`, then `models` table, then 'Generic', useful for robust ML data prep.* 49 | 50 | --- 51 | 52 | ## 💡 Practice Tips 53 | 54 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 55 | - **ML Use Case**: `COALESCE` ensures no nulls in features or labels, critical for ML training. 56 | - **Try This**: Add 5 rows to `predictions` with some `model_name` nulls, then use `COALESCE`. Check with `SELECT COUNT(*) WHERE model_name IS NULL`. 57 | - **Note**: List enough arguments to cover null cases—test with varied data. 58 | 59 | --- 60 | 61 | ## 🚀 Next Steps 62 | 63 | - **Level Up**: Combine `COALESCE` with `CASE` for advanced logic or `NULLIF` for null creation. 64 | - **Portfolio Win**: Add a `COALESCE` query to `irohanportfolio.netlify.app`, showing ML data cleaning. 65 | - **Challenge**: Clean null `score`s with a default for a portfolio ML report. 66 | 67 | Clean like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/01 Data Query Language (DQL)/04 Conditional Logic/03 Nullif/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master NULLIF - Control Nulls in Your ML Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | **NULLIF** turns a value into null if it matches a condition, perfect for handling unwanted ML data like placeholder scores or generic names. It’s your trick for fine-tuning datasets. This guide will teach you `NULLIF` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand the Goal**: Learn how `NULLIF` converts values to null based on a match. 12 | 2. **Study Syntax**: See `NULLIF` with two arguments. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Play with Matches**: Test different values to see nulls appear. 15 | 5. **ML Angle**: Use `NULLIF` to clean specific values for ML preprocessing. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT NULLIF(column, value) AS alias 23 | FROM table_name; 24 | ``` 25 | 26 | - **Example 1: Clear Placeholder Names**: 27 | ```sql 28 | SELECT prediction_id, 29 | NULLIF(model_name, 'Generic') AS cleaned_name 30 | FROM predictions; 31 | ``` 32 | *Turns 'Generic' `model_name`s to null, like removing ML placeholder data.* 33 | 34 | - **Example 2: Zero Score to Null**: 35 | ```sql 36 | SELECT prediction_id, model_id, 37 | NULLIF(score, 0.0) AS valid_score 38 | FROM predictions; 39 | ``` 40 | *Converts `score` of 0.0 to null, great for filtering invalid ML results.* 41 | 42 | - **Example 3: Combine with COALESCE**: 43 | ```sql 44 | SELECT prediction_id, 45 | COALESCE(NULLIF(model_name, 'Unknown'), 'Default') AS final_name 46 | FROM predictions; 47 | ``` 48 | *Changes 'Unknown' to null, then defaults to 'Default', useful for ML data cleanup.* 49 | 50 | --- 51 | 52 | ## 💡 Practice Tips 53 | 54 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 55 | - **ML Use Case**: `NULLIF` helps remove invalid values (e.g., dummy scores) before ML training. 56 | - **Try This**: Add 5 rows to `predictions` with `model_name` as 'Generic', then use `NULLIF`. Verify nulls with `SELECT COUNT(*) WHERE model_name IS NULL`. 57 | - **Tip**: Pair `NULLIF` with `COALESCE` for full null control—test both together. 58 | 59 | --- 60 | 61 | ## 🚀 Next Steps 62 | 63 | - **Go Deeper**: Use `NULLIF` with `CASE` for complex logic or `COALESCE` for null handling. 64 | - **Portfolio Boost**: Add a `NULLIF` query to `irohanportfolio.netlify.app`, explaining ML data prep. 65 | - **Challenge**: Convert `score` 0.0 to null for a portfolio ML report. 66 | 67 | Null like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/01 INSERT/01 Single Row Insert/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Single Row Insert - Add ML Data One at a Time! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Single Row Insert** adds one row to a table, perfect for logging a new ML prediction or feature record. It’s your starting point for building datasets with precision. This guide will walk you through learning `INSERT` for single rows with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `INSERT` adds a single row with specified values. 12 | 2. **Study the Syntax**: Learn the structure and column-value mapping. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL or MySQL. 14 | 4. **Experiment**: Insert different values to see the table grow. 15 | 5. **Apply to ML**: Use single row inserts to log ML model outputs or test data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | INSERT INTO table_name (column1, column2, ...) 23 | VALUES (value1, value2, ...); 24 | ``` 25 | 26 | - **Example 1: Add a Prediction**: 27 | ```sql 28 | INSERT INTO predictions (prediction_id, model_id, score, prediction_date, model_name) 29 | VALUES (1, 101, 0.95, '2025-04-01', 'NeuralNet'); 30 | ``` 31 | *Adds a new prediction, like logging an ML model’s output.* 32 | 33 | - **Example 2: Minimal Columns**: 34 | ```sql 35 | INSERT INTO predictions (prediction_id, model_id, score) 36 | VALUES (2, 102, 0.82); 37 | ``` 38 | *Inserts a row with some columns omitted (e.g., `model_name` as null), great for quick ML data entry.* 39 | 40 | - **Example 3: Date-Focused Insert**: 41 | ```sql 42 | INSERT INTO predictions (prediction_id, model_id, prediction_date, model_name) 43 | VALUES (3, 103, '2025-04-02', 'XGBoost'); 44 | ``` 45 | *Logs a prediction with a date, useful for ML time-series datasets.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test inserts. 52 | - **ML Use Case**: Single row inserts are key for logging individual ML predictions or feature records during experiments. 53 | - **Try This**: Create a `predictions` table, insert a row with `score = 0.9`, then verify with `SELECT * FROM predictions`. 54 | - **Debug**: Ensure column names match table schema—mismatches cause errors. Check with `DESCRIBE predictions`. 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Deepen Skills**: Explore `Multiple Row Insert` for bulk data or `Insert from Select` for dynamic ML data. 61 | - **Portfolio Boost**: Add a single row insert query to `irohanportfolio.netlify.app`, explaining its ML logging role. 62 | - **Challenge**: Insert a prediction with `model_name = 'DeepLearning'` for a portfolio ML dataset. 63 | 64 | Insert like a pro, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/01 INSERT/02 Multiple Row Insert/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Multiple Row Insert - Bulk Up Your ML Data Fast! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Multiple Row Insert** adds several rows at once, ideal for loading batches of ML predictions or feature sets efficiently. It’s your shortcut for scaling datasets. This guide will teach you multi-row `INSERT` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: See how multi-row `INSERT` stacks values for bulk entry. 12 | 2. **Learn Syntax**: Study the comma-separated value list format. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Tweak Batches**: Add or remove rows to test efficiency. 15 | 5. **ML Spin**: Use multi-row inserts to populate ML training or test datasets. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | INSERT INTO table_name (column1, column2, ...) 23 | VALUES 24 | (value1a, value2a, ...), 25 | (value1b, value2b, ...), 26 | ...; 27 | ``` 28 | 29 | - **Example 1: Batch Predictions**: 30 | ```sql 31 | INSERT INTO predictions (prediction_id, model_id, score, prediction_date, model_name) 32 | VALUES 33 | (4, 101, 0.88, '2025-04-03', 'NeuralNet'), 34 | (5, 102, 0.76, '2025-04-03', 'XGBoost'), 35 | (6, 103, 0.92, '2025-04-03', 'DeepLearning'); 36 | ``` 37 | *Adds three predictions at once, like logging a day’s ML outputs.* 38 | 39 | - **Example 2: Partial Columns**: 40 | ```sql 41 | INSERT INTO predictions (prediction_id, model_id, score) 42 | VALUES 43 | (7, 104, 0.85), 44 | (8, 105, 0.91); 45 | ``` 46 | *Inserts two rows with `score` only, great for quick ML data batches.* 47 | 48 | - **Example 3: Mixed Data**: 49 | ```sql 50 | INSERT INTO predictions (prediction_id, model_id, score, model_name) 51 | VALUES 52 | (9, 106, 0.79, 'RandomForest'), 53 | (10, 107, 0.94, 'GradientBoost'); 54 | ``` 55 | *Loads varied ML model data, useful for diverse dataset creation.* 56 | 57 | --- 58 | 59 | ## 💡 Practice Tips 60 | 61 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 62 | - **ML Use Case**: Multi-row inserts speed up loading ML experiment results or feature batches for training. 63 | - **Try This**: Insert 5 rows into `predictions` with different `score`s, then check with `SELECT COUNT(*) FROM predictions`. 64 | - **Note**: Ensure consistent column counts per row—mismatches break the query. Test small batches first. 65 | 66 | --- 67 | 68 | ## 🚀 Next Steps 69 | 70 | - **Level Up**: Try `Insert from Select` for dynamic bulk inserts or `Single Row Insert` for precision. 71 | - **Portfolio Win**: Add a multi-row insert query to `irohanportfolio.netlify.app`, showing ML dataset creation. 72 | - **Challenge**: Insert 3 predictions with varied `model_name`s for a portfolio ML dataset. 73 | 74 | Bulk up like a champ, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/02 UPDATE/01 Single Column Update/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Single Column Update - Tweak Your ML Data with Precision! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Single Column Update** changes one column’s values in a table, perfect for fixing ML prediction scores or updating model names. It’s your tool for precise data edits. This guide will walk you through learning `UPDATE` for a single column with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `UPDATE` targets one column across rows. 12 | 2. **Study the Syntax**: Learn the `SET` clause for single-column changes. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL or MySQL. 14 | 4. **Experiment**: Update different values and check results. 15 | 5. **Apply to ML**: Use single-column updates to correct ML dataset errors. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | UPDATE table_name 23 | SET column = value 24 | [WHERE condition]; 25 | ``` 26 | 27 | - **Example 1: Fix Model Name**: 28 | ```sql 29 | UPDATE predictions 30 | SET model_name = 'NeuralNet' 31 | WHERE model_id = 101; 32 | ``` 33 | *Updates `model_name` for `model_id 101`, like correcting ML metadata.* 34 | 35 | - **Example 2: Adjust Score**: 36 | ```sql 37 | UPDATE predictions 38 | SET score = 0.9 39 | WHERE prediction_id = 1; 40 | ``` 41 | *Changes a specific `score`, great for fixing ML prediction errors.* 42 | 43 | - **Example 3: Standardize Date**: 44 | ```sql 45 | UPDATE predictions 46 | SET prediction_date = '2025-04-01' 47 | WHERE prediction_date IS NULL; 48 | ``` 49 | *Sets null `prediction_date`s to a default, useful for ML data cleanup.* 50 | 51 | --- 52 | 53 | ## 💡 Practice Tips 54 | 55 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test updates. 56 | - **ML Use Case**: Single-column updates help fix individual ML features, like scores or labels, for accurate models. 57 | - **Try This**: Create `predictions` with 5 rows, update `score` to 0.85 for `prediction_id = 2`, then verify with `SELECT * FROM predictions`. 58 | - **Debug**: Always test without `WHERE` in a sandbox—omitting it updates all rows! Use `SELECT` first to preview. 59 | 60 | --- 61 | 62 | ## 🚀 Next Steps 63 | 64 | - **Deepen Skills**: Explore `Multiple Column Update` for broader changes or `Update with Conditions` for precise targeting. 65 | - **Portfolio Boost**: Add a single-column update query to `irohanportfolio.netlify.app`, explaining its ML data fix role. 66 | - **Challenge**: Update `model_name` for a specific `model_id` for a portfolio ML dataset. 67 | 68 | Tweak like a pro, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/02 UPDATE/02 Multiple Column Update/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Multiple Column Update - Revamp Your ML Data in One Go! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Multiple Column Update** changes several columns at once, ideal for updating ML prediction scores and model names together. It’s your shortcut for batch data fixes. This guide will teach you multi-column `UPDATE` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: See how `UPDATE` handles multiple columns in one query. 12 | 2. **Learn Syntax**: Study the `SET` clause with comma-separated assignments. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Tweak Updates**: Modify multiple columns to test outcomes. 15 | 5. **ML Spin**: Use multi-column updates to align ML datasets for training. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | UPDATE table_name 23 | SET column1 = value1, column2 = value2, ... 24 | [WHERE condition]; 25 | ``` 26 | 27 | - **Example 1: Update Score and Name**: 28 | ```sql 29 | UPDATE predictions 30 | SET score = 0.95, model_name = 'DeepLearning' 31 | WHERE model_id = 102; 32 | ``` 33 | *Updates `score` and `model_name` for `model_id 102`, like refining ML results.* 34 | 35 | - **Example 2: Fix Date and Score**: 36 | ```sql 37 | UPDATE predictions 38 | SET prediction_date = '2025-04-02', score = 0.88 39 | WHERE prediction_id = 3; 40 | ``` 41 | *Corrects `prediction_date` and `score`, great for ML time-series fixes.* 42 | 43 | - **Example 3: Standardize Multiple Fields**: 44 | ```sql 45 | UPDATE predictions 46 | SET model_name = 'XGBoost', score = 0.9 47 | WHERE score < 0.5; 48 | ``` 49 | *Sets low `score`s to 0.9 and updates `model_name`, useful for ML data normalization.* 50 | 51 | --- 52 | 53 | ## 💡 Practice Tips 54 | 55 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 56 | - **ML Use Case**: Multi-column updates streamline ML data prep by fixing multiple features at once, like scores and metadata. 57 | - **Try This**: Add 5 rows to `predictions`, update `score` and `model_name` for `model_id = 103`, then check with `SELECT * FROM predictions`. 58 | - **Note**: Preview changes with `SELECT`—bulk updates without `WHERE` can overwrite everything! 59 | 60 | --- 61 | 62 | ## 🚀 Next Steps 63 | 64 | - **Level Up**: Try `Update with Conditions` for targeted edits or `Single Column Update` for focused changes. 65 | - **Portfolio Win**: Add a multi-column update query to `irohanportfolio.netlify.app`, showing ML data refinement. 66 | - **Challenge**: Update `score` and `prediction_date` for low scores in a portfolio ML dataset. 67 | 68 | Revamp like a champ, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/02 UPDATE/03 Update with Coditions/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Update with Conditions - Fine-Tune Your ML Data Like a Boss! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Update with Conditions** uses `WHERE` to target specific rows, perfect for tweaking ML datasets like boosting low scores or fixing outdated predictions. It’s your key to precise data updates. This guide will show you how to learn conditional `UPDATE` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Targeting**: Learn how `WHERE` filters rows for updates. 12 | 2. **Study Syntax**: See `UPDATE` with `SET` and `WHERE` clauses. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Play with Conditions**: Test different `WHERE` clauses to refine updates. 15 | 5. **ML Angle**: Use conditional updates to clean or adjust ML data for models. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | UPDATE table_name 23 | SET column1 = value1, column2 = value2, ... 24 | WHERE condition; 25 | ``` 26 | 27 | - **Example 1: Boost Low Scores**: 28 | ```sql 29 | UPDATE predictions 30 | SET score = score + 0.1 31 | WHERE score < 0.7; 32 | ``` 33 | *Increases `score`s below 0.7, like adjusting weak ML predictions.* 34 | 35 | - **Example 2: Update by Date**: 36 | ```sql 37 | UPDATE predictions 38 | SET model_name = 'UpdatedModel', prediction_date = '2025-04-03' 39 | WHERE prediction_date < '2025-01-01'; 40 | ``` 41 | *Fixes old predictions’ `model_name` and `prediction_date`, great for ML dataset refresh.* 42 | 43 | - **Example 3: Target Model ID**: 44 | ```sql 45 | UPDATE predictions 46 | SET score = 0.92 47 | WHERE model_id = 101 AND score IS NULL; 48 | ``` 49 | *Sets null `score`s for `model_id 101` to 0.92, useful for ML data completion.* 50 | 51 | --- 52 | 53 | ## 💡 Practice Tips 54 | 55 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 56 | - **ML Use Case**: Conditional updates help refine ML datasets by targeting specific issues, like nulls or outdated records. 57 | - **Try This**: Create `predictions` with 10 rows, update `score` to 0.9 where `model_id = 102`, then verify with `SELECT * FROM predictions WHERE model_id = 102`. 58 | - **Tip**: Test `WHERE` with `SELECT` first to confirm rows—wrong conditions can update unintended data. 59 | 60 | --- 61 | 62 | ## 🚀 Next Steps 63 | 64 | - **Go Deeper**: Combine `Update with Conditions` with `Multiple Column Update` for complex fixes or `DELETE` for data removal. 65 | - **Portfolio Boost**: Add a conditional update query to `irohanportfolio.netlify.app`, explaining ML data cleaning. 66 | - **Challenge**: Update `score` and `model_name` for old `prediction_date`s in a portfolio ML dataset. 67 | 68 | Fine-tune like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/03 DELETE/01 Delete with Conditions/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Delete with Conditions - Clean Your ML Data Like a Pro! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Delete with Conditions** uses `WHERE` to remove specific rows, perfect for pruning bad ML predictions or outdated records. It’s your tool for targeted data cleanup. This guide will walk you through learning conditional `DELETE` with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Targeting**: Learn how `WHERE` pinpoints rows to delete. 12 | 2. **Study the Syntax**: See `DELETE` with `WHERE` clauses. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL or MySQL. 14 | 4. **Test Conditions**: Experiment with different `WHERE` clauses to refine deletions. 15 | 5. **Apply to ML**: Use conditional deletes to remove invalid ML data for better models. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | DELETE FROM table_name 23 | WHERE condition; 24 | ``` 25 | 26 | - **Example 1: Remove Low Scores**: 27 | ```sql 28 | DELETE FROM predictions 29 | WHERE score < 0.5; 30 | ``` 31 | *Deletes predictions with low `score`s, like removing weak ML results.* 32 | 33 | - **Example 2: Clear Old Predictions**: 34 | ```sql 35 | DELETE FROM predictions 36 | WHERE prediction_date < '2025-01-01'; 37 | ``` 38 | *Removes outdated predictions, great for refreshing ML datasets.* 39 | 40 | - **Example 3: Delete by Model**: 41 | ```sql 42 | DELETE FROM predictions 43 | WHERE model_id = 101 AND model_name = 'OldModel'; 44 | ``` 45 | *Erases specific model’s data, useful for ML experiment cleanup.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test deletes. 52 | - **ML Use Case**: Conditional deletes help clean ML datasets by removing outliers or obsolete records, improving model accuracy. 53 | - **Try This**: Create `predictions` with 10 rows, delete where `score < 0.6`, then verify with `SELECT COUNT(*) FROM predictions`. 54 | - **Debug**: Test `WHERE` with `SELECT` first—wrong conditions can delete too much! Always backup data in production. 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Deepen Skills**: Explore `Delete All Rows` for full table resets or combine with `UPDATE` for data fixes before deletion. 61 | - **Portfolio Boost**: Add a conditional delete query to `irohanportfolio.netlify.app`, explaining its ML data cleanup role. 62 | - **Challenge**: Delete predictions older than 2025-03-01 for a portfolio ML dataset. 63 | 64 | Clean like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/03 DELETE/02 Delete All Rows/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Delete All Rows - Reset Your ML Data with Ease! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Delete All Rows** wipes every row from a table without dropping it, ideal for resetting ML datasets or clearing test data. It’s your quick way to start fresh. This guide will teach you how to learn `DELETE` for all rows with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand how `DELETE` without `WHERE` clears all rows. 12 | 2. **Learn Syntax**: Study the simple `DELETE` or `TRUNCATE` options. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Verify Results**: Check table emptiness after deletion. 15 | 5. **ML Spin**: Use full deletes to reset ML experiment tables or prep for new data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- Basic Delete 23 | DELETE FROM table_name; 24 | 25 | -- Alternative: Truncate (faster, no transaction log) 26 | TRUNCATE TABLE table_name; 27 | ``` 28 | 29 | - **Example 1: Clear Predictions**: 30 | ```sql 31 | DELETE FROM predictions; 32 | ``` 33 | *Removes all rows from `predictions`, like resetting an ML dataset.* 34 | 35 | - **Example 2: Truncate Table**: 36 | ```sql 37 | TRUNCATE TABLE predictions; 38 | ``` 39 | *Wipes `predictions` instantly, great for clearing ML test data.* 40 | 41 | - **Example 3: Delete with Count Check**: 42 | ```sql 43 | -- Check rows first 44 | SELECT COUNT(*) FROM predictions; 45 | -- Then delete 46 | DELETE FROM predictions; 47 | ``` 48 | *Verifies row count before clearing, useful for ML data management.* 49 | 50 | --- 51 | 52 | ## 💡 Practice Tips 53 | 54 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 55 | - **ML Use Case**: Full deletes reset ML tables for new experiments or clean up after model testing. 56 | - **Try This**: Add 5 rows to `predictions`, run `DELETE`, then confirm with `SELECT * FROM predictions` (should be empty). 57 | - **Note**: `DELETE` is reversible with transactions; `TRUNCATE` is faster but permanent—test in a sandbox! Use `SELECT COUNT(*)` to confirm before deleting. 58 | 59 | --- 60 | 61 | ## 🚀 Next Steps 62 | 63 | - **Level Up**: Try `Delete with Conditions` for selective cleanup or `INSERT` to repopulate tables. 64 | - **Portfolio Win**: Add a full delete query to `irohanportfolio.netlify.app`, showing ML dataset reset. 65 | - **Challenge**: Clear `predictions` and reinsert 3 rows for a portfolio ML dataset. 66 | 67 | Reset like a boss, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/02 Data Manipulation Language (DML)/03 DELETE/02 Delete All Rows/README.md: -------------------------------------------------------------------------------- 1 | # 🗑️ Delete All Rows - Clear Your Table Completely 2 | 3 | ## 🌟 Overview 4 | 5 | The **Delete All Rows** is a `DELETE` statement that removes **every row** from a table without conditions, effectively emptying it while preserving the table structure. It’s a powerful tool for resetting datasets or clearing test data. In AI/ML, deleting all rows is used to refresh staging tables, reset test environments, or prepare for new data loads. 6 | 7 | --- 8 | 9 | ## 📜 Syntax 10 | 11 | ```sql 12 | DELETE FROM table_name; 13 | ``` 14 | 15 | - **Basic Example**: 16 | ```sql 17 | DELETE FROM predictions; 18 | ``` 19 | - **With Transaction**: 20 | ```sql 21 | BEGIN; 22 | DELETE FROM predictions; 23 | COMMIT; 24 | ``` 25 | - **Alternative (Some DBs)**: 26 | ```sql 27 | TRUNCATE TABLE predictions; 28 | ``` 29 | 30 | --- 31 | 32 | ## 💡 Use Cases in AI/ML 33 | 34 | - **Test Reset**: Clear test predictions (e.g., `DELETE FROM test_predictions`). 35 | - **Staging Cleanup**: Empty staging tables (e.g., `DELETE FROM staging_data`). 36 | - **Data Refresh**: Remove all records before reloading (e.g., `DELETE FROM model_outputs`). 37 | - **Environment Prep**: Reset tables for new experiments (e.g., `DELETE FROM experiment_logs`). 38 | 39 | --- 40 | 41 | ## 🔑 Key Features 42 | 43 | - **Complete Removal**: Deletes all rows in one statement. 44 | - **Structure Preserved**: Keeps table schema, indexes, and constraints intact. 45 | - **Fast Execution**: Typically faster than conditional deletes for full clears. 46 | - **Constraint Awareness**: May be restricted by foreign keys. 47 | 48 | --- 49 | 50 | ## ✅ Best Practices 51 | 52 | - **Confirm Intent**: Double-check you want all rows gone—there’s no undo without backups. 53 | - **Use Transactions**: Enclose in `BEGIN`/`COMMIT` or `ROLLBACK` for safety. 54 | - **Consider TRUNCATE**: Use `TRUNCATE` for faster clears if constraints allow. 55 | - **Backup Data**: Save critical data before deleting everything. 56 | 57 | --- 58 | 59 | ## ⚠️ Common Pitfalls 60 | 61 | - **Accidental Deletion**: Running without a `WHERE` clause clears everything unintentionally. 62 | - **Foreign Key Issues**: Deletes may fail if rows are referenced elsewhere. 63 | - **No Rollback**: Without transactions, deleted data is gone permanently. 64 | - **Confusion with DROP**: `DELETE` keeps the table; `DROP` removes it entirely. 65 | 66 | --- 67 | 68 | ## 📝 Additional Notes 69 | 70 | - **Database Variations**: 71 | - MySQL/PostgreSQL/SQL Server: `DELETE FROM table_name` works universally. 72 | - PostgreSQL: `TRUNCATE` is faster but skips triggers; `DELETE` supports `RETURNING`. 73 | - **Performance**: `TRUNCATE` resets auto-increment counters; `DELETE` doesn’t. 74 | - **Restrictions**: Foreign keys may block deletion unless cascaded or disabled. -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/01 Tables/02 Alter Table/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master ALTER TABLE - Upgrade Your ML Data Schema! 2 | 3 | ## 🌟 Welcome 4 | 5 | **ALTER TABLE** modifies a table’s structure, ideal for adding columns to ML datasets or tweaking data types for better model inputs. It’s your tool for evolving database designs. This guide will teach you `ALTER TABLE` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Learn how `ALTER TABLE` changes columns or constraints. 12 | 2. **Study Syntax**: Explore commands like `ADD`, `MODIFY`, or `DROP COLUMN`. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Tweak Structures**: Add or change columns to test schema updates. 15 | 5. **ML Spin**: Use `ALTER TABLE` to refine ML datasets for experiments. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | ALTER TABLE table_name 23 | ADD column_name datatype [constraints] | 24 | MODIFY COLUMN column_name datatype [constraints] | 25 | DROP COLUMN column_name; 26 | ``` 27 | 28 | - **Example 1: Add Confidence Column**: 29 | ```sql 30 | ALTER TABLE predictions 31 | ADD confidence FLOAT; 32 | ``` 33 | *Adds a `confidence` column to `predictions`, like enhancing ML output data.* 34 | 35 | - **Example 2: Change Data Type**: 36 | ```sql 37 | ALTER TABLE model_metrics 38 | MODIFY COLUMN accuracy DECIMAL(5,4); 39 | ``` 40 | *Updates `accuracy` to precise decimals, great for ML metric storage.* 41 | 42 | - **Example 3: Drop Unused Column**: 43 | ```sql 44 | ALTER TABLE predictions 45 | DROP COLUMN model_name; 46 | ``` 47 | *Removes `model_name` if unused, streamlining ML datasets.* 48 | 49 | --- 50 | 51 | ## 💡 Practice Tips 52 | 53 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 54 | - **ML Use Case**: `ALTER TABLE` adapts schemas for ML needs, like adding features or optimizing types. 55 | - **Try This**: Create `predictions`, add a `version` column (`INT`), insert a row, then verify with `DESCRIBE predictions`. 56 | - **Note**: Test in a sandbox—`DROP COLUMN` is permanent! Check table with `SELECT *` before altering. 57 | 58 | --- 59 | 60 | ## 🚀 Next Steps 61 | 62 | - **Level Up**: Try `Create Table` for new schemas or `Drop Table` for cleanup. 63 | - **Portfolio Win**: Add an `ALTER TABLE` command to `irohanportfolio.netlify.app`, showing ML schema evolution. 64 | - **Challenge**: Add a `loss` column to `model_metrics` for a portfolio ML dataset. 65 | 66 | Upgrade like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/01 Tables/03 Drop Table/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master DROP TABLE - Clear Your ML Data Slate! 2 | 3 | ## 🌟 Welcome 4 | 5 | **DROP TABLE** deletes an entire table and its data, perfect for removing outdated ML datasets or test tables. It’s your reset button for database cleanup. This guide will show you how to learn `DROP TABLE` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand the Impact**: Learn how `DROP TABLE` wipes tables completely. 12 | 2. **Study Syntax**: See the simple `DROP TABLE` command. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Verify Deletion**: Confirm tables are gone after dropping. 15 | 5. **ML Angle**: Use `DROP TABLE` to remove obsolete ML data structures. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | DROP TABLE table_name; 23 | -- Optional: Check existence 24 | DROP TABLE IF EXISTS table_name; 25 | ``` 26 | 27 | - **Example 1: Drop Predictions**: 28 | ```sql 29 | DROP TABLE predictions; 30 | ``` 31 | *Deletes the `predictions` table, like clearing an old ML dataset.* 32 | 33 | - **Example 2: Safe Drop**: 34 | ```sql 35 | DROP TABLE IF EXISTS model_metrics; 36 | ``` 37 | *Removes `model_metrics` safely, great for ML test cleanup without errors.* 38 | 39 | - **Example 3: Verify Before Drop**: 40 | ```sql 41 | -- Check table 42 | SELECT * FROM feature_store LIMIT 1; 43 | -- Then drop 44 | DROP TABLE feature_store; 45 | ``` 46 | *Confirms table exists before deletion, useful for ML data management.* 47 | 48 | --- 49 | 50 | ## 💡 Practice Tips 51 | 52 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 53 | - **ML Use Case**: `DROP TABLE` clears unused ML tables, freeing space for new experiments. 54 | - **Try This**: Create `model_metrics`, add 3 rows, drop it, then confirm with `SELECT * FROM model_metrics` (should fail). 55 | - **Tip**: Use `IF EXISTS` to avoid errors—dropping non-existent tables crashes queries. Always backup critical ML data! 56 | 57 | --- 58 | 59 | ## 🚀 Next Steps 60 | 61 | - **Go Deeper**: Explore `Truncate Table` for data-only resets or `Create Table` to rebuild. 62 | - **Portfolio Boost**: Add a `DROP TABLE` command to `irohanportfolio.netlify.app`, explaining ML cleanup. 63 | - **Challenge**: Drop a test table and recreate it for a portfolio ML dataset. 64 | 65 | Clear like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/01 Tables/03 Drop Table/README.md: -------------------------------------------------------------------------------- 1 | # 🗑️ Drop Table - Removing Tables Permanently 2 | 3 | ## 🌟 Overview 4 | 5 | The **DROP TABLE** statement in SQL is a DDL command used to **permanently delete a table** and all its data from the database. It’s a destructive operation that removes both the table’s structure and contents, freeing up space. In AI/ML, `DROP TABLE` is used to clean up obsolete datasets, remove temporary tables, or reset experimental schemas during development. 6 | 7 | --- 8 | 9 | ## 📜 Syntax 10 | 11 | ```sql 12 | DROP TABLE [IF EXISTS] table_name [CASCADE | RESTRICT]; 13 | ``` 14 | 15 | - **Basic Example**: 16 | ```sql 17 | DROP TABLE temp_results; 18 | ``` 19 | - **Safe Drop**: 20 | ```sql 21 | DROP TABLE IF EXISTS old_predictions; 22 | ``` 23 | - **With Cascade**: 24 | ```sql 25 | DROP TABLE orders CASCADE; 26 | ``` 27 | 28 | --- 29 | 30 | ## 💡 Use Cases in AI/ML 31 | 32 | - **Cleanup**: Remove outdated tables (e.g., `DROP TABLE old_training_data`). 33 | - **Experiment Reset**: Delete temporary tables (e.g., `DROP TABLE test_features`). 34 | - **Schema Refactoring**: Drop tables during redesign (e.g., `DROP TABLE legacy_models`). 35 | - **Space Management**: Free storage by removing unused tables (e.g., `DROP TABLE archived_logs`). 36 | 37 | --- 38 | 39 | ## 🔑 Key Features 40 | 41 | - **Permanent Deletion**: Removes table structure, data, and associated indexes/triggers. 42 | - **IF EXISTS**: Prevents errors if the table doesn’t exist. 43 | - **CASCADE Option**: Drops dependent objects (e.g., foreign keys) in some databases. 44 | - **Auto-Commit**: Changes are final, with no rollback option in most systems. 45 | 46 | --- 47 | 48 | ## ✅ Best Practices 49 | 50 | - **Confirm Necessity**: Double-check the table is no longer needed before dropping. 51 | - **Use IF EXISTS**: Avoid errors in scripts when tables may not exist. 52 | - **Backup Data**: Export critical data before dropping to prevent loss. 53 | - **Test in Sandbox**: Practice drops in a non-production environment. 54 | 55 | --- 56 | 57 | ## ⚠️ Common Pitfalls 58 | 59 | - **Data Loss**: Dropping a table deletes all data permanently; no undo without backups. 60 | - **Dependency Issues**: Dropping tables with foreign keys may fail without `CASCADE`. 61 | - **Accidental Drops**: Mistyping table names can destroy wrong tables. 62 | - **Performance**: Dropping large tables may temporarily lock the database. 63 | 64 | --- 65 | 66 | ## 📝 Additional Notes 67 | 68 | - **Database Variations**: 69 | - MySQL: Supports `IF EXISTS` and `CASCADE`. 70 | - PostgreSQL: Offers `CASCADE` to drop dependent constraints. 71 | - SQL Server: Uses `IF EXISTS` but lacks `CASCADE` (drop dependencies manually). 72 | - **Recovery**: Regular backups or transaction logs are needed for recovery. 73 | - **Alternatives**: Use `TRUNCATE` if only data removal is needed, preserving structure. -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/01 Tables/04 Truncate Table/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master TRUNCATE TABLE - Reset Your ML Data Fast! 2 | 3 | ## 🌟 Welcome 4 | 5 | **TRUNCATE TABLE** removes all rows but keeps the table structure, ideal for resetting ML datasets without losing schema for new experiments. It’s your quick data wipe tool. This guide will teach you `TRUNCATE TABLE` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand how `TRUNCATE` clears data, not structure. 12 | 2. **Learn Syntax**: Study `TRUNCATE` vs. `DELETE`. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Check Results**: Verify table is empty but exists after truncating. 15 | 5. **ML Spin**: Use `TRUNCATE` to prep ML tables for fresh data runs. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | TRUNCATE TABLE table_name; 23 | ``` 24 | 25 | - **Example 1: Reset Predictions**: 26 | ```sql 27 | TRUNCATE TABLE predictions; 28 | ``` 29 | *Clears all `predictions` rows, like resetting an ML dataset for retraining.* 30 | 31 | - **Example 2: Truncate Metrics**: 32 | ```sql 33 | TRUNCATE TABLE model_metrics; 34 | ``` 35 | *Wipes `model_metrics` data, great for starting new ML performance logs.* 36 | 37 | - **Example 3: Verify Before Truncate**: 38 | ```sql 39 | -- Check rows 40 | SELECT COUNT(*) FROM predictions; 41 | -- Then truncate 42 | TRUNCATE TABLE predictions; 43 | ``` 44 | *Confirms row count before reset, useful for ML data refresh.* 45 | 46 | --- 47 | 48 | ## 💡 Practice Tips 49 | 50 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 51 | - **ML Use Case**: `TRUNCATE TABLE` resets ML tables for new experiments, keeping schemas intact for pipelines. 52 | - **Try This**: Create `predictions`, add 5 rows, truncate, then check with `SELECT * FROM predictions` (should be empty). 53 | - **Note**: `TRUNCATE` is faster than `DELETE` but irreversible—test in a sandbox and backup ML data! 54 | 55 | --- 56 | 57 | ## 🚀 Next Steps 58 | 59 | - **Level Up**: Compare with `Drop Table` for full removal or `INSERT` to repopulate. 60 | - **Portfolio Win**: Add a `TRUNCATE TABLE` command to `irohanportfolio.netlify.app`, showing ML data reset. 61 | - **Challenge**: Truncate `model_metrics` and insert new metrics for a portfolio ML dataset. 62 | 63 | Reset like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/01 Tables/04 Truncate Table/README.md: -------------------------------------------------------------------------------- 1 | 2 | # 🧹 Truncate Table - Clearing All Data 3 | 4 | ## 🌟 Overview 5 | 6 | The **TRUNCATE TABLE** statement in SQL is a DDL command used to **delete all rows** from a table while preserving its structure, including columns, constraints, and indexes. Unlike `DROP TABLE`, it keeps the table intact for reuse. In AI/ML, `TRUNCATE TABLE` is useful for resetting datasets, clearing temporary results, or preparing tables for new data during experiments. 7 | 8 | --- 9 | 10 | ## 📜 Syntax 11 | 12 | ```sql 13 | TRUNCATE TABLE table_name [CASCADE | RESTRICT]; 14 | ``` 15 | 16 | - **Basic Example**: 17 | ```sql 18 | TRUNCATE TABLE temp_predictions; 19 | ``` 20 | - **With Cascade**: 21 | ```sql 22 | TRUNCATE TABLE orders CASCADE; 23 | ``` 24 | 25 | --- 26 | 27 | ## 💡 Use Cases in AI/ML 28 | 29 | - **Dataset Reset**: Clear training data for new runs (e.g., `TRUNCATE TABLE training_data`). 30 | - **Experiment Cleanup**: Remove temporary results (e.g., `TRUNCATE TABLE test_metrics`). 31 | - **Data Refresh**: Prepare tables for fresh data (e.g., `TRUNCATE TABLE staging_table`). 32 | - **Performance Testing**: Reset tables for benchmarking (e.g., `TRUNCATE TABLE performance_logs`). 33 | 34 | --- 35 | 36 | ## 🔑 Key Features 37 | 38 | - **Data Removal**: Deletes all rows, leaving the table structure intact. 39 | - **Speed**: Faster than `DELETE` as it doesn’t scan rows or log individual deletions. 40 | - **CASCADE Option**: Handles dependent foreign keys in some databases. 41 | - **Auto-Commit**: Changes are permanent, like other DDL commands. 42 | 43 | --- 44 | 45 | ## ✅ Best Practices 46 | 47 | - **Verify Need**: Ensure data is no longer required before truncating. 48 | - **Use CASCADE Carefully**: Only use when dependent tables should also be cleared. 49 | - **Backup Data**: Save critical data before truncation, as recovery is difficult. 50 | - **Combine with Transactions**: Some databases allow `TRUNCATE` in transactions for safety. 51 | 52 | --- 53 | 54 | ## ⚠️ Common Pitfalls 55 | 56 | - **Irreversible Action**: Truncation cannot be undone without backups. 57 | - **Foreign Key Issues**: Truncating tables with dependencies fails without `CASCADE`. 58 | - **Trigger Impact**: Unlike `DELETE`, `TRUNCATE` may not fire row-level triggers. 59 | - **Misuse vs. DELETE**: Using `TRUNCATE` when selective deletion is needed removes too much data. 60 | 61 | --- 62 | 63 | ## 📝 Additional Notes 64 | 65 | - **Database Variations**: 66 | - MySQL: Supports `CASCADE` for foreign keys. 67 | - PostgreSQL: Allows `CASCADE` and `RESTART IDENTITY` for sequences. 68 | - SQL Server: Doesn’t support `CASCADE`; drop constraints first. 69 | - **Performance**: Ideal for large tables due to minimal logging compared to `DELETE`. 70 | - **Restrictions**: Cannot truncate tables referenced by active views or cursors in some systems. -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/02 Constraints/03 Unique/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master UNIQUE - Keep Your ML Data Distinct! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Unique** constraint prevents duplicate values in a column, perfect for ensuring ML model names or feature IDs stay distinct. It’s your guard against redundant data. This guide will show you `UNIQUE` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand how `UNIQUE` enforces distinct values. 12 | 2. **Learn Syntax**: Study defining it in `CREATE TABLE` or `ALTER TABLE`. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Test Duplicates**: Insert repeated values to trigger errors. 15 | 5. **ML Angle**: Use `UNIQUE` to maintain clean ML metadata. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- In CREATE TABLE 23 | CREATE TABLE table_name ( 24 | column_name datatype UNIQUE, 25 | ... 26 | ); 27 | 28 | -- In ALTER TABLE 29 | ALTER TABLE table_name 30 | ADD UNIQUE (column_name); 31 | ``` 32 | 33 | - **Example 1: Unique Model Names**: 34 | ```sql 35 | CREATE TABLE models ( 36 | model_id INT PRIMARY KEY, 37 | model_name VARCHAR(50) UNIQUE 38 | ); 39 | ``` 40 | *Ensures no duplicate `model_name`s in ML models.* 41 | 42 | - **Example 2: Unique Feature IDs**: 43 | ```sql 44 | CREATE TABLE feature_store ( 45 | feature_id INT UNIQUE, 46 | value FLOAT 47 | ); 48 | ``` 49 | *Keeps `feature_id`s distinct for ML feature tracking.* 50 | 51 | - **Example 3: Add Unique Constraint**: 52 | ```sql 53 | ALTER TABLE predictions 54 | ADD UNIQUE (model_name); 55 | ``` 56 | *Applies `UNIQUE` to `model_name` in an existing ML table.* 57 | 58 | --- 59 | 60 | ## 💡 Practice Tips 61 | 62 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 63 | - **ML Use Case**: `UNIQUE` prevents duplicate ML metadata, like model or feature names, for clean datasets. 64 | - **Try This**: Create `models`, insert two rows with the same `model_name`, and verify the error. Check with `SELECT *`. 65 | - **Tip**: `UNIQUE` allows nulls (unlike `PRIMARY KEY`)—test with null inserts. 66 | 67 | --- 68 | 69 | ## 🚀 Next Steps 70 | 71 | - **Go Deeper**: Explore `Primary Key` for stricter uniqueness or `Check` for value rules. 72 | - **Portfolio Boost**: Add a `UNIQUE` table to `irohanportfolio.netlify.app`, explaining ML data cleanliness. 73 | - **Challenge**: Create a table with a unique ML feature column for a portfolio dataset. 74 | 75 | Stay distinct like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/02 Constraints/04 Not Null/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master NOT NULL - Ensure Your ML Data Stays Complete! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Not Null** constraint forces a column to have a value, ideal for mandatory ML fields like prediction scores or metric IDs. It’s your shield against missing data. This guide will teach you `NOT NULL` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand the Rule**: Learn how `NOT NULL` bans null values. 12 | 2. **Study Syntax**: See how to apply it in `CREATE TABLE` or `ALTER TABLE`. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Test Nulls**: Try inserting nulls to see errors. 15 | 5. **ML Spin**: Use `NOT NULL` to enforce complete ML datasets. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- In CREATE TABLE 23 | CREATE TABLE table_name ( 24 | column_name datatype NOT NULL, 25 | ... 26 | ); 27 | 28 | -- In ALTER TABLE 29 | ALTER TABLE table_name 30 | MODIFY COLUMN column_name datatype NOT NULL; 31 | ``` 32 | 33 | - **Example 1: Mandatory Prediction ID**: 34 | ```sql 35 | CREATE TABLE predictions ( 36 | prediction_id INT NOT NULL, 37 | model_id INT, 38 | score FLOAT 39 | ); 40 | ``` 41 | *Ensures `prediction_id` is always set for ML predictions.* 42 | 43 | - **Example 2: Required Accuracy**: 44 | ```sql 45 | CREATE TABLE model_metrics ( 46 | metric_id INT, 47 | model_id INT, 48 | accuracy FLOAT NOT NULL 49 | ); 50 | ``` 51 | *Forces `accuracy` values for ML metrics.* 52 | 53 | - **Example 3: Add Not Null**: 54 | ```sql 55 | ALTER TABLE predictions 56 | MODIFY COLUMN score FLOAT NOT NULL; 57 | ``` 58 | *Makes `score` mandatory in an existing ML table.* 59 | 60 | --- 61 | 62 | ## 💡 Practice Tips 63 | 64 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 65 | - **ML Use Case**: `NOT NULL` ensures critical ML fields, like scores, are always populated for modeling. 66 | - **Try This**: Create `predictions`, try inserting a row with null `score`, and check the error. Verify with `DESCRIBE predictions`. 67 | - **Note**: Existing nulls block `NOT NULL` additions—clean data with `UPDATE` first. 68 | 69 | --- 70 | 71 | ## 🚀 Next Steps 72 | 73 | - **Level Up**: Pair `NOT NULL` with `Default` for fallback values or `Primary Key` for IDs. 74 | - **Portfolio Win**: Add a `NOT NULL` table to `irohanportfolio.netlify.app`, showing ML data completeness. 75 | - **Challenge**: Create a table with a non-null ML score column for a portfolio dataset. 76 | 77 | Stay complete like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/02 Constraints/05 Check/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master CHECK - Guard Your ML Data Quality! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Check** constraint enforces rules on column values, perfect for ensuring ML scores stay within valid ranges or dates make sense. It’s your gatekeeper for data quality. This guide will show you `CHECK` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Rule**: Understand how `CHECK` validates data. 12 | 2. **Learn Syntax**: Study defining it in `CREATE TABLE` or `ALTER TABLE`. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Test Limits**: Insert invalid values to trigger errors. 15 | 5. **ML Angle**: Use `CHECK` to keep ML data within realistic bounds. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- In CREATE TABLE 23 | CREATE TABLE table_name ( 24 | column_name datatype CHECK (condition), 25 | ... 26 | ); 27 | 28 | -- In ALTER TABLE 29 | ALTER TABLE table_name 30 | ADD CONSTRAINT constraint_name CHECK (condition); 31 | ``` 32 | 33 | - **Example 1: Valid Scores**: 34 | ```sql 35 | CREATE TABLE predictions ( 36 | prediction_id INT, 37 | score FLOAT CHECK (score >= 0 AND score <= 1) 38 | ); 39 | ``` 40 | *Ensures `score`s are between 0 and 1 for ML predictions.* 41 | 42 | - **Example 2: Positive Accuracy**: 43 | ```sql 44 | CREATE TABLE model_metrics ( 45 | metric_id INT, 46 | accuracy FLOAT CHECK (accuracy > 0) 47 | ); 48 | ``` 49 | *Forces `accuracy` to be positive for ML metrics.* 50 | 51 | - **Example 3: Add Check Constraint**: 52 | ```sql 53 | ALTER TABLE predictions 54 | ADD CONSTRAINT valid_date CHECK (prediction_date >= '2025-01-01'); 55 | ``` 56 | *Restricts `prediction_date` to 2025 onward in an ML table.* 57 | 58 | --- 59 | 60 | ## 💡 Practice Tips 61 | 62 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL (MySQL support varies). 63 | - **ML Use Case**: `CHECK` keeps ML data valid, like ensuring scores or metrics fit model expectations. 64 | - **Try This**: Create `predictions`, insert a `score` of 1.5, and verify the error. Check with `SELECT *`. 65 | - **Tip**: Name constraints for clarity—unnamed ones are hard to drop later. 66 | 67 | --- 68 | 69 | ## 🚀 Next Steps 70 | 71 | - **Go Deeper**: Combine `CHECK` with `Not Null` or `Default` for robust rules. 72 | - **Portfolio Boost**: Add a `CHECK` table to `irohanportfolio.netlify.app`, explaining ML data validation. 73 | - **Challenge**: Create a table with a score range check for a portfolio ML dataset. 74 | 75 | Guard like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/02 Constraints/06 Default/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master DEFAULT - Set Smart ML Data Fallbacks! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Default** constraint assigns a fallback value when no data is provided, ideal for setting standard ML scores or dates. It’s your trick for consistent datasets. This guide will teach you `DEFAULT` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Fallbacks**: Learn how `DEFAULT` fills missing values. 12 | 2. **Study Syntax**: See how to set it in `CREATE TABLE` or `ALTER TABLE`. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Test Defaults**: Insert rows without values to see defaults applied. 15 | 5. **ML Spin**: Use `DEFAULT` to streamline ML data entry. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- In CREATE TABLE 23 | CREATE TABLE table_name ( 24 | column_name datatype DEFAULT value, 25 | ... 26 | ); 27 | 28 | -- In ALTER TABLE 29 | ALTER TABLE table_name 30 | ALTER COLUMN column_name SET DEFAULT value; 31 | ``` 32 | 33 | - **Example 1: Default Score**: 34 | ```sql 35 | CREATE TABLE predictions ( 36 | prediction_id INT, 37 | score FLOAT DEFAULT 0.5 38 | ); 39 | ``` 40 | *Sets `score` to 0.5 if unspecified, like a baseline for ML predictions.* 41 | 42 | - **Example 2: Default Date**: 43 | ```sql 44 | CREATE TABLE model_metrics ( 45 | metric_id INT, 46 | log_date DATE DEFAULT '2025-01-01' 47 | ); 48 | ``` 49 | *Uses a default `log_date` for ML metrics.* 50 | 51 | - **Example 3: Add Default**: 52 | ```sql 53 | ALTER TABLE predictions 54 | ALTER COLUMN model_name SET DEFAULT 'Unknown'; 55 | ``` 56 | *Adds a default `model_name` to an ML table.* 57 | 58 | --- 59 | 60 | ## 💡 Practice Tips 61 | 62 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 63 | - **ML Use Case**: `DEFAULT` simplifies ML data prep by auto-filling fields like scores or labels. 64 | - **Try This**: Create `predictions`, insert a row without `score`, and check the default with `SELECT *`. 65 | - **Note**: Defaults don’t apply to explicit nulls—test with `INSERT` variations. 66 | 67 | --- 68 | 69 | ## 🚀 Next Steps 70 | 71 | - **Level Up**: Pair `DEFAULT` with `Not Null` for mandatory defaults or `Check` for value rules. 72 | - **Portfolio Win**: Add a `DEFAULT` table to `irohanportfolio.netlify.app`, showing ML data consistency. 73 | - **Challenge**: Create a table with a default ML score for a portfolio dataset. 74 | 75 | Fallback like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/03 Views/01 Create View/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master CREATE VIEW - Simplify Your ML Data Queries! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **CREATE VIEW** command builds a virtual table from a query, perfect for streamlining ML data reporting like summarizing model scores or metrics. It’s your shortcut to reusable queries. This guide will walk you through learning `CREATE VIEW` with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Concept**: Understand how views store queries, not data. 12 | 2. **Study the Syntax**: Learn to define views with `CREATE VIEW`. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL or MySQL. 14 | 4. **Experiment**: Create views with different ML-focused queries. 15 | 5. **Apply to ML**: Use views to simplify ML dataset analysis or reporting. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | CREATE VIEW view_name AS 23 | SELECT column1, column2, ... 24 | FROM table_name 25 | [WHERE condition]; 26 | ``` 27 | 28 | - **Example 1: High-Score Predictions**: 29 | ```sql 30 | CREATE VIEW high_score_predictions AS 31 | SELECT prediction_id, model_id, score, model_name 32 | FROM predictions 33 | WHERE score >= 0.9; 34 | ``` 35 | *Creates a view of top ML predictions for quick performance analysis.* 36 | 37 | - **Example 2: Model Accuracy Summary**: 38 | ```sql 39 | CREATE VIEW model_accuracy AS 40 | SELECT model_id, AVG(accuracy) AS avg_accuracy 41 | FROM model_metrics 42 | GROUP BY model_id; 43 | ``` 44 | *Builds a view summarizing ML model accuracy, great for comparisons.* 45 | 46 | - **Example 3: Recent Predictions**: 47 | ```sql 48 | CREATE VIEW recent_predictions AS 49 | SELECT prediction_id, score, prediction_date 50 | FROM predictions 51 | WHERE prediction_date >= '2025-04-01'; 52 | ``` 53 | *Shows recent ML predictions, ideal for time-series reporting.* 54 | 55 | --- 56 | 57 | ## 💡 Practice Tips 58 | 59 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test views. 60 | - **ML Use Case**: Views simplify ML data access, like filtering high-performing predictions for model evaluation. 61 | - **Try This**: Create `predictions`, add 5 rows, make a view for `score > 0.8`, then query it with `SELECT * FROM high_score_predictions`. 62 | - **Debug**: Test the `SELECT` query alone first—views fail if the query’s invalid. Use `DESCRIBE view_name` to check columns. 63 | 64 | --- 65 | 66 | ## 🚀 Next Steps 67 | 68 | - **Deepen Skills**: Explore `Alter View` to tweak views or `Drop View` to remove them. 69 | - **Portfolio Boost**: Add a `CREATE VIEW` command to `irohanportfolio.netlify.app`, explaining its ML reporting role. 70 | - **Challenge**: Create a view for top ML metrics and query it for a portfolio dataset. 71 | 72 | Simplify like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/03 Views/02 Alter View/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master ALTER VIEW - Upgrade Your ML Data Views! 2 | 3 | ## 🌟 Welcome 4 | 5 | **ALTER VIEW** updates an existing view’s query, ideal for refining ML reporting like adjusting score thresholds or adding metrics. It’s your tool for keeping views relevant. This guide will teach you `ALTER VIEW` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Updates**: Learn how `ALTER VIEW` redefines a view’s query. 12 | 2. **Study Syntax**: See how it mirrors `CREATE VIEW` with modifications. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Tweak Views**: Alter queries to test new outputs. 15 | 5. **ML Spin**: Use `ALTER VIEW` to adapt ML data summaries for analysis. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | ALTER VIEW view_name AS 23 | SELECT column1, column2, ... 24 | FROM table_name 25 | [WHERE condition]; 26 | ``` 27 | 28 | - **Example 1: Tighten Score Filter**: 29 | ```sql 30 | ALTER VIEW high_score_predictions AS 31 | SELECT prediction_id, model_id, score, model_name 32 | FROM predictions 33 | WHERE score >= 0.95; 34 | ``` 35 | *Updates the view to show only elite ML predictions.* 36 | 37 | - **Example 2: Expand Metrics View**: 38 | ```sql 39 | ALTER VIEW model_accuracy AS 40 | SELECT model_id, AVG(accuracy) AS avg_accuracy, COUNT(*) AS metric_count 41 | FROM model_metrics 42 | GROUP BY model_id; 43 | ``` 44 | *Modifies the view to include a count of ML metrics.* 45 | 46 | - **Example 3: Shift Date Range**: 47 | ```sql 48 | ALTER VIEW recent_predictions AS 49 | SELECT prediction_id, score, prediction_date, model_name 50 | FROM predictions 51 | WHERE prediction_date >= '2025-03-01'; 52 | ``` 53 | *Adjusts the view to capture a broader ML prediction window.* 54 | 55 | --- 56 | 57 | ## 💡 Practice Tips 58 | 59 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 60 | - **ML Use Case**: `ALTER VIEW` keeps ML reporting current, like updating thresholds for model evaluation. 61 | - **Try This**: Create a `high_score_predictions` view, alter it to `score >= 0.85`, then query with `SELECT * FROM high_score_predictions`. 62 | - **Note**: `ALTER VIEW` replaces the query—test the new `SELECT` first to avoid errors. 63 | 64 | --- 65 | 66 | ## 🚀 Next Steps 67 | 68 | - **Level Up**: Try `Create View` for new views or `Drop View` for cleanup. 69 | - **Portfolio Win**: Add an `ALTER VIEW` command to `irohanportfolio.netlify.app`, showing ML query refinement. 70 | - **Challenge**: Alter a view to include extra ML metrics for a portfolio dataset. 71 | 72 | Upgrade like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/03 Views/03 Drop View/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master DROP VIEW - Clear Outdated ML Views! 2 | 3 | ## 🌟 Welcome 4 | 5 | **DROP VIEW** removes a view from the database, perfect for cleaning up unused ML query snapshots like old prediction summaries. It’s your tool for tidy schemas. This guide will show you `DROP VIEW` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Cleanup**: Learn how `DROP VIEW` deletes views without touching tables. 12 | 2. **Study Syntax**: See the simple `DROP VIEW` command. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Verify Removal**: Confirm views are gone after dropping. 15 | 5. **ML Angle**: Use `DROP VIEW` to remove obsolete ML reporting views. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | DROP VIEW view_name; 23 | -- Optional: Safe drop 24 | DROP VIEW IF EXISTS view_name; 25 | ``` 26 | 27 | - **Example 1: Drop Predictions View**: 28 | ```sql 29 | DROP VIEW high_score_predictions; 30 | ``` 31 | *Removes the `high_score_predictions` view, like clearing an old ML report.* 32 | 33 | - **Example 2: Safe Drop Metrics**: 34 | ```sql 35 | DROP VIEW IF EXISTS model_accuracy; 36 | ``` 37 | *Deletes `model_accuracy` safely, great for ML cleanup without errors.* 38 | 39 | - **Example 3: Verify Before Drop**: 40 | ```sql 41 | -- Check view 42 | SELECT * FROM recent_predictions LIMIT 1; 43 | -- Then drop 44 | DROP VIEW recent_predictions; 45 | ``` 46 | *Confirms view exists before removal, useful for ML data management.* 47 | 48 | --- 49 | 50 | ## 💡 Practice Tips 51 | 52 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 53 | - **ML Use Case**: `DROP VIEW` cleans up outdated ML views, freeing schema space for new reports. 54 | - **Try This**: Create a `model_accuracy` view, query it, drop it, then try `SELECT * FROM model_accuracy` (should fail). 55 | - **Tip**: Use `IF EXISTS` to avoid errors—dropping non-existent views crashes queries. Check views with `SELECT *` first. 56 | 57 | --- 58 | 59 | ## 🚀 Next Steps 60 | 61 | - **Go Deeper**: Explore `Create View` to rebuild views or `Alter View` to tweak them. 62 | - **Portfolio Boost**: Add a `DROP VIEW` command to `irohanportfolio.netlify.app`, explaining ML schema cleanup. 63 | - **Challenge**: Drop a view and recreate it with new ML filters for a portfolio dataset. 64 | 65 | Clear like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/03 Data Definition Language (DDL)/03 Views/03 Drop View/README.md: -------------------------------------------------------------------------------- 1 | # 🗑️ Drop View - Removing Virtual Tables 2 | 3 | ## 🌟 Overview 4 | 5 | The **DROP VIEW** statement in SQL is a DDL command used to **permanently remove a view** from the database, eliminating its definition without affecting underlying tables. It’s a lightweight operation since views don’t store data. In AI/ML, `DROP VIEW` is used to clean up obsolete views, simplify schemas, or remove temporary views created for experiments. 6 | 7 | --- 8 | 9 | ## 📜 Syntax 10 | 11 | ```sql 12 | DROP VIEW [IF EXISTS] view_name [CASCADE | RESTRICT]; 13 | ``` 14 | 15 | - **Basic Example**: 16 | ```sql 17 | DROP VIEW temp_report; 18 | ``` 19 | - **Safe Drop**: 20 | ```sql 21 | DROP VIEW IF EXISTS old_metrics; 22 | ``` 23 | - **With Cascade**: 24 | ```sql 25 | DROP VIEW user_summary CASCADE; 26 | ``` 27 | 28 | --- 29 | 30 | ## 💡 Use Cases in AI/ML 31 | 32 | - **Schema Cleanup**: Remove outdated views (e.g., `DROP VIEW old_user_features`). 33 | - **Experiment Reset**: Delete temporary views (e.g., `DROP VIEW test_predictions`). 34 | - **Security Management**: Eliminate views exposing sensitive data (e.g., `DROP VIEW public_data`). 35 | - **Pipeline Optimization**: Drop unused views to streamline query planning (e.g., `DROP VIEW legacy_report`). 36 | 37 | --- 38 | 39 | ## 🔑 Key Features 40 | 41 | - **Non-Destructive**: Only removes the view definition, not underlying table data. 42 | - **IF EXISTS**: Prevents errors if the view doesn’t exist. 43 | - **CASCADE Option**: Drops dependent objects (e.g., other views) in some databases. 44 | - **Auto-Commit**: Changes are final, typical for DDL commands. 45 | 46 | --- 47 | 48 | ## ✅ Best Practices 49 | 50 | - **Verify Necessity**: Confirm the view is no longer needed before dropping. 51 | - **Use IF EXISTS**: Avoid script errors when views may not exist. 52 | - **Check Dependencies**: Ensure no queries or processes rely on the view. 53 | - **Document Removal**: Log dropped views for team awareness. 54 | 55 | --- 56 | 57 | ## ⚠️ Common Pitfalls 58 | 59 | - **Dependency Breaks**: Dropping views can disrupt dependent applications or views. 60 | - **Accidental Drops**: Mistyping view names may remove the wrong view. 61 | - **No Undo**: Dropped views require re-creation from scratch, needing the original query. 62 | - **Permission Issues**: Lack of privileges can prevent dropping in shared databases. 63 | 64 | --- 65 | 66 | ## 📝 Additional Notes 67 | 68 | - **Database Variations**: 69 | - MySQL: Supports `IF EXISTS`; no `CASCADE` option. 70 | - PostgreSQL: Offers `CASCADE` to drop dependent views. 71 | - SQL Server: Supports `IF EXISTS` but requires manual dependency checks. 72 | - **Performance**: Dropping views is fast, as no data is stored. 73 | - **Recovery**: Keep view creation scripts in version control for easy restoration. -------------------------------------------------------------------------------- /SQL Fundamentals/04 Data Control Language (DCL)/01 GRANT/01 Grant Permissions/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master GRANT Permissions - Secure Your ML Data Access! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **GRANT Permissions** command gives users specific database privileges, like reading ML prediction data or updating model scores. It’s your key to controlling who accesses your AI pipelines. This guide will walk you through learning `GRANT` permissions with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `GRANT` assigns privileges like `SELECT` or `INSERT`. 12 | 2. **Study the Syntax**: Learn to specify users, privileges, and objects. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL or PostgreSQL. 14 | 4. **Test Access**: Log in as the user to verify permissions work. 15 | 5. **Apply to ML**: Use `GRANT` to secure ML datasets for team workflows. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | GRANT privilege [, privilege ...] 23 | ON object_name 24 | TO user_name [, user_name ...]; 25 | ``` 26 | 27 | - **Example 1: Read-Only ML Data**: 28 | ```sql 29 | GRANT SELECT ON predictions TO 'ml_user'; 30 | ``` 31 | *Allows `ml_user` to query ML predictions, perfect for data analysts.* 32 | 33 | - **Example 2: Update Scores**: 34 | ```sql 35 | GRANT SELECT, UPDATE ON predictions TO 'data_engineer'; 36 | ``` 37 | *Gives `data_engineer` read and update access to tweak ML scores.* 38 | 39 | - **Example 3: Table Creation**: 40 | ```sql 41 | GRANT CREATE ON DATABASE ml_db TO 'ml_admin'; 42 | ``` 43 | *Permits `ml_admin` to create tables in the ML database.* 44 | 45 | --- 46 | 47 | ## 💡 Practice Tips 48 | 49 | - **Tool Up**: Use MySQL Workbench or [DBeaver](https://dbeaver.io) to test permissions. 50 | - **ML Use Case**: `GRANT` secures ML data by limiting who can read or modify predictions, ensuring pipeline safety. 51 | - **Try This**: Create a `predictions` table, grant `SELECT` to a test user, log in as them, and run `SELECT * FROM predictions`. 52 | - **Debug**: Verify user privileges with `SHOW GRANTS FOR 'user_name'`—missing grants block access. 53 | 54 | --- 55 | 56 | ## 🚀 Next Steps 57 | 58 | - **Deepen Skills**: Explore `Grant Roles` for group permissions or `REVOKE` to undo access. 59 | - **Portfolio Boost**: Add a `GRANT` command to `irohanportfolio.netlify.app`, explaining its ML security role. 60 | - **Challenge**: Grant `SELECT` on a predictions table for an ML user in a portfolio dataset. 61 | 62 | Secure like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/04 Data Control Language (DCL)/01 GRANT/02 Grant Roles/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master GRANT Roles - Streamline ML Team Access! 2 | 3 | ## 🌟 Welcome 4 | 5 | **GRANT Roles** assigns predefined roles to users, simplifying access control for ML teams, like giving data scientists read-write access. It’s your trick for scalable permissions. This guide will teach you `GRANT` roles with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Roles**: Learn how roles bundle privileges for users. 12 | 2. **Study Syntax**: See how to create and grant roles. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Test Role Access**: Assign roles and verify user capabilities. 15 | 5. **ML Spin**: Use roles to manage ML team access to datasets. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- Create a role 23 | CREATE ROLE role_name; 24 | 25 | -- Grant privileges to role 26 | GRANT privilege [, privilege ...] 27 | ON object_name 28 | TO role_name; 29 | 30 | -- Grant role to user 31 | GRANT role_name TO user_name [, user_name ...]; 32 | ``` 33 | 34 | - **Example 1: Data Scientist Role**: 35 | ```sql 36 | CREATE ROLE data_scientist; 37 | GRANT SELECT, INSERT, UPDATE ON predictions TO data_scientist; 38 | GRANT data_scientist TO 'ml_user'; 39 | ``` 40 | *Sets up a role for ML data scientists and assigns it to `ml_user`.* 41 | 42 | - **Example 2: Analyst Role**: 43 | ```sql 44 | CREATE ROLE analyst; 45 | GRANT SELECT ON predictions TO analyst; 46 | GRANT analyst TO 'report_user'; 47 | ``` 48 | *Gives `report_user` read-only ML data access via a role.* 49 | 50 | - **Example 3: Admin Role**: 51 | ```sql 52 | CREATE ROLE db_admin; 53 | GRANT ALL ON DATABASE ml_db TO db_admin; 54 | GRANT db_admin TO 'ml_admin'; 55 | ``` 56 | *Grants full ML database control to `ml_admin` through a role.* 57 | 58 | --- 59 | 60 | ## 💡 Practice Tips 61 | 62 | - **Tool Time**: Use [pgAdmin](https://www.pgadmin.org) or MySQL Workbench to manage roles. 63 | - **ML Use Case**: Roles streamline ML workflows by grouping permissions for data scientists or analysts. 64 | - **Try This**: Create a `data_scientist` role, grant it `SELECT` on `predictions`, assign to a user, and test with `SELECT * FROM predictions`. 65 | - **Note**: Check role assignments with `SELECT * FROM information_schema.role_table_grants`—unassigned roles do nothing! 66 | 67 | --- 68 | 69 | ## 🚀 Next Steps 70 | 71 | - **Level Up**: Try `Grant Permissions` for direct access or `REVOKE` to remove roles. 72 | - **Portfolio Win**: Add a `GRANT ROLE` command to `irohanportfolio.netlify.app`, showing ML team management. 73 | - **Challenge**: Create an ML analyst role and assign it for a portfolio dataset. 74 | 75 | Streamline like a boss, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/04 Data Control Language (DCL)/02 REVOKE/01 Revoke Permissions/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master REVOKE Permissions - Tighten Your ML Data Security! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **REVOKE Permissions** command removes specific database privileges, like stopping a user from reading ML predictions or updating scores. It’s your tool for locking down AI pipelines. This guide will walk you through learning `REVOKE` permissions with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `REVOKE` takes away privileges like `SELECT` or `UPDATE`. 12 | 2. **Study the Syntax**: Learn to specify users, privileges, and objects. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL or PostgreSQL. 14 | 4. **Test Restrictions**: Log in as the user to confirm access is blocked. 15 | 5. **Apply to ML**: Use `REVOKE` to secure ML datasets from unauthorized access. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | REVOKE privilege [, privilege ...] 23 | ON object_name 24 | FROM user_name [, user_name ...]; 25 | ``` 26 | 27 | - **Example 1: Block Read Access**: 28 | ```sql 29 | REVOKE SELECT ON predictions FROM 'ml_user'; 30 | ``` 31 | *Removes `ml_user`’s ability to query ML predictions, tightening security.* 32 | 33 | - **Example 2: Stop Updates**: 34 | ```sql 35 | REVOKE UPDATE ON predictions FROM 'data_engineer'; 36 | ``` 37 | *Prevents `data_engineer` from modifying ML scores, ensuring data integrity.* 38 | 39 | - **Example 3: Remove Table Creation**: 40 | ```sql 41 | REVOKE CREATE ON DATABASE ml_db FROM 'ml_admin'; 42 | ``` 43 | *Stops `ml_admin` from creating new tables in the ML database.* 44 | 45 | --- 46 | 47 | ## 💡 Practice Tips 48 | 49 | - **Tool Up**: Use MySQL Workbench or [DBeaver](https://dbeaver.io) to test revoking permissions. 50 | - **ML Use Case**: `REVOKE` protects ML data by restricting access, like blocking updates to critical predictions. 51 | - **Try This**: Grant `SELECT` on `predictions` to a test user, revoke it, then try `SELECT * FROM predictions` as the user (should fail). 52 | - **Debug**: Check remaining privileges with `SHOW GRANTS FOR 'user_name'`—revoked permissions should be gone. 53 | 54 | --- 55 | 56 | ## 🚀 Next Steps 57 | 58 | - **Deepen Skills**: Explore `Revoke Roles` for group-level control or `GRANT` to restore access. 59 | - **Portfolio Boost**: Add a `REVOKE` command to `irohanportfolio.netlify.app`, explaining its ML security role. 60 | - **Challenge**: Revoke `UPDATE` on a predictions table for an ML user in a portfolio dataset. 61 | 62 | Lock down like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/04 Data Control Language (DCL)/02 REVOKE/02 Revoke Roles/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master REVOKE Roles - Streamline ML Team Security! 2 | 3 | ## 🌟 Welcome 4 | 5 | **REVOKE Roles** removes roles from users, cutting off bundled privileges like data scientist access to ML datasets. It’s your trick for scalable security management. This guide will teach you `REVOKE` roles with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Roles**: Learn how revoking roles strips users of grouped privileges. 12 | 2. **Study Syntax**: See how to revoke roles from users. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Test Access**: Verify users lose role-based permissions. 15 | 5. **ML Spin**: Use `REVOKE` roles to manage ML team access securely. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | REVOKE role_name [, role_name ...] 23 | FROM user_name [, user_name ...]; 24 | ``` 25 | 26 | - **Example 1: Remove Data Scientist Role**: 27 | ```sql 28 | REVOKE data_scientist FROM 'ml_user'; 29 | ``` 30 | *Strips `ml_user` of ML data scientist privileges, like `SELECT` or `UPDATE`.* 31 | 32 | - **Example 2: Revoke Analyst Role**: 33 | ```sql 34 | REVOKE analyst FROM 'report_user'; 35 | ``` 36 | *Removes `report_user`’s read-only access to ML predictions via the role.* 37 | 38 | - **Example 3: Revoke Admin Role**: 39 | ```sql 40 | REVOKE db_admin FROM 'ml_admin'; 41 | ``` 42 | *Takes away `ml_admin`’s full control over the ML database.* 43 | 44 | --- 45 | 46 | ## 💡 Practice Tips 47 | 48 | - **Tool Time**: Use [pgAdmin](https://www.pgadmin.org) or MySQL Workbench to manage roles. 49 | - **ML Use Case**: Revoking roles ensures ML data security by cutting off team access when needed, like after a project ends. 50 | - **Try This**: Create a `data_scientist` role with `SELECT` on `predictions`, grant it to a user, revoke it, then test `SELECT * FROM predictions` (should fail). 51 | - **Note**: Verify role removal with `SELECT * FROM information_schema.role_table_grants`—users lose all role privileges. 52 | 53 | --- 54 | 55 | ## 🚀 Next Steps 56 | 57 | - **Level Up**: Try `Revoke Permissions` for specific privilege control or `GRANT` to reassign roles. 58 | - **Portfolio Win**: Add a `REVOKE ROLE` command to `irohanportfolio.netlify.app`, showing ML team security. 59 | - **Challenge**: Revoke an ML analyst role from a user for a portfolio dataset. 60 | 61 | Secure like a boss, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/05 Transaction Control Language (TCL)/01 COMMIT/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master COMMIT - Lock in Your ML Data Changes! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **COMMIT** command saves all changes in a transaction, perfect for finalizing ML data updates like new predictions or model scores. It’s your key to making data permanent. This guide will walk you through learning `COMMIT` with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Concept**: Understand how `COMMIT` makes transaction changes permanent. 12 | 2. **Study the Syntax**: Learn the simple `COMMIT` command. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL or MySQL. 14 | 4. **Test Persistence**: Insert data, commit, and verify it stays. 15 | 5. **Apply to ML**: Use `COMMIT` to save ML dataset updates securely. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | COMMIT; 23 | ``` 24 | 25 | - **Example 1: Save New Predictions**: 26 | ```sql 27 | BEGIN; 28 | INSERT INTO predictions VALUES (1, 101, 0.9, '2025-04-01', 'NeuralNet'); 29 | COMMIT; 30 | ``` 31 | *Saves a new ML prediction to the database.* 32 | 33 | - **Example 2: Confirm Score Updates**: 34 | ```sql 35 | BEGIN; 36 | UPDATE predictions SET score = 0.95 WHERE prediction_id = 1; 37 | COMMIT; 38 | ``` 39 | *Makes an ML score update permanent.* 40 | 41 | - **Example 3: Batch Insert Commit**: 42 | ```sql 43 | BEGIN; 44 | INSERT INTO predictions VALUES (2, 102, 0.85, '2025-04-02', 'XGBoost'); 45 | INSERT INTO predictions VALUES (3, 102, 0.88, '2025-04-02', 'XGBoost'); 46 | COMMIT; 47 | ``` 48 | *Commits multiple ML predictions at once.* 49 | 50 | --- 51 | 52 | ## 💡 Practice Tips 53 | 54 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL Workbench to test transactions. 55 | - **ML Use Case**: `COMMIT` ensures ML data updates, like new predictions, are safely stored for model training. 56 | - **Try This**: Start a transaction, insert a row into `predictions`, commit, then verify with `SELECT * FROM predictions`. 57 | - **Debug**: Check data after `COMMIT`—uncommitted changes vanish on session end. Use `SELECT` to confirm. 58 | 59 | --- 60 | 61 | ## 🚀 Next Steps 62 | 63 | - **Deepen Skills**: Explore `ROLLBACK` to undo changes or `SAVEPOINT` for partial commits. 64 | - **Portfolio Boost**: Add a `COMMIT` example to `irohanportfolio.netlify.app`, explaining its ML data role. 65 | - **Challenge**: Insert and commit ML predictions for a portfolio dataset. 66 | 67 | Lock in like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/05 Transaction Control Language (TCL)/02 ROLLBACK/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master ROLLBACK - Undo ML Data Mistakes! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **ROLLBACK** command discards transaction changes, perfect for reverting ML data errors like incorrect predictions or score updates. It’s your safety net for data integrity. This guide will teach you `ROLLBACK` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Undo**: Learn how `ROLLBACK` cancels uncommitted changes. 12 | 2. **Study Syntax**: See the straightforward `ROLLBACK` command. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Test Reverts**: Make changes, rollback, and check data. 15 | 5. **ML Spin**: Use `ROLLBACK` to fix ML dataset errors before saving. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | ROLLBACK; 23 | ``` 24 | 25 | - **Example 1: Undo Insert**: 26 | ```sql 27 | BEGIN; 28 | INSERT INTO predictions VALUES (1, 101, 0.9, '2025-04-01', 'NeuralNet'); 29 | ROLLBACK; 30 | ``` 31 | *Discards a new ML prediction, keeping the table unchanged.* 32 | 33 | - **Example 2: Revert Update**: 34 | ```sql 35 | BEGIN; 36 | UPDATE predictions SET score = 0.1 WHERE prediction_id = 1; 37 | ROLLBACK; 38 | ``` 39 | *Cancels an ML score update, restoring original data.* 40 | 41 | - **Example 3: Cancel Batch Changes**: 42 | ```sql 43 | BEGIN; 44 | INSERT INTO predictions VALUES (2, 102, 0.85, '2025-04-02', 'XGBoost'); 45 | DELETE FROM predictions WHERE prediction_id = 1; 46 | ROLLBACK; 47 | ``` 48 | *Undoes multiple ML data changes in one go.* 49 | 50 | --- 51 | 52 | ## 💡 Practice Tips 53 | 54 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 55 | - **ML Use Case**: `ROLLBACK` saves ML datasets from bad updates, like fixing wrong prediction scores. 56 | - **Try This**: Start a transaction, update `score` in `predictions`, rollback, then verify with `SELECT * FROM predictions`. 57 | - **Note**: `ROLLBACK` only works before `COMMIT`—test changes with `SELECT` first. 58 | 59 | --- 60 | 61 | ## 🚀 Next Steps 62 | 63 | - **Level Up**: Try `COMMIT` to save changes or `SAVEPOINT` for partial rollbacks. 64 | - **Portfolio Win**: Add a `ROLLBACK` example to `irohanportfolio.netlify.app`, showing ML error recovery. 65 | - **Challenge**: Update and rollback ML scores for a portfolio dataset. 66 | 67 | Undo like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/05 Transaction Control Language (TCL)/03 SET TRANSACTION/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master SET TRANSACTION - Control Your ML Data Flow! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **SET TRANSACTION** command configures transaction properties, like read-only mode for ML data queries or isolation levels for consistency. It’s your tool for tailoring transaction behavior. This guide will show you `SET TRANSACTION` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand how `SET TRANSACTION` sets rules for transactions. 12 | 2. **Study Syntax**: Learn options like `READ ONLY` or `ISOLATION LEVEL`. 13 | 3. **Run Examples**: Try the commands below in a database like PostgreSQL. 14 | 4. **Test Settings**: Apply settings and verify behavior. 15 | 5. **ML Angle**: Use `SET TRANSACTION` to ensure safe ML data operations. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SET TRANSACTION [READ ONLY | READ WRITE] [ISOLATION LEVEL level]; 23 | ``` 24 | 25 | - **Example 1: Read-Only Query**: 26 | ```sql 27 | BEGIN; 28 | SET TRANSACTION READ ONLY; 29 | SELECT * FROM predictions; 30 | COMMIT; 31 | ``` 32 | *Ensures no changes during ML data analysis.* 33 | 34 | - **Example 2: Strict Isolation**: 35 | ```sql 36 | BEGIN; 37 | SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; 38 | UPDATE predictions SET score = 0.95 WHERE prediction_id = 1; 39 | COMMIT; 40 | ``` 41 | *Uses high isolation for consistent ML updates.* 42 | 43 | - **Example 3: Read-Write Mode**: 44 | ```sql 45 | BEGIN; 46 | SET TRANSACTION READ WRITE; 47 | INSERT INTO predictions VALUES (1, 101, 0.9, '2025-04-01', 'NeuralNet'); 48 | COMMIT; 49 | ``` 50 | *Sets explicit write mode for ML data inserts.* 51 | 52 | --- 53 | 54 | ## 💡 Practice Tips 55 | 56 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL (MySQL support varies). 57 | - **ML Use Case**: `SET TRANSACTION` protects ML data queries, like ensuring read-only access for reporting. 58 | - **Try This**: Start a transaction, set `READ ONLY`, try an `INSERT` (should fail), then query `predictions`. 59 | - **Tip**: Test `ISOLATION LEVEL` with multiple sessions—`SERIALIZABLE` prevents conflicts. 60 | 61 | --- 62 | 63 | ## 🚀 Next Steps 64 | 65 | - **Go Deeper**: Combine with `COMMIT` or `ROLLBACK` for full control. 66 | - **Portfolio Boost**: Add a `SET TRANSACTION` example to `irohanportfolio.netlify.app`, explaining ML data safety. 67 | - **Challenge**: Use `READ ONLY` for an ML query in a portfolio dataset. 68 | 69 | Control like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/01 Joins/01 Inner Join/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master INNER JOIN - Match Your ML Data Perfectly! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **INNER JOIN** combines rows from two tables where conditions match, perfect for linking ML predictions to model details. It’s your go-to for precise data pairing. This guide will walk you through learning `INNER JOIN` with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `INNER JOIN` keeps only matched rows. 12 | 2. **Study the Syntax**: Learn to join tables with `ON` conditions. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL or MySQL. 14 | 4. **Test Matches**: Join tables and verify results. 15 | 5. **Apply to ML**: Use `INNER JOIN` to merge ML datasets for analysis. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT columns 23 | FROM table1 24 | INNER JOIN table2 25 | ON table1.column = table2.column; 26 | ``` 27 | 28 | - **Example 1: Link Predictions to Models**: 29 | ```sql 30 | SELECT p.prediction_id, p.score, m.model_name 31 | FROM predictions p 32 | INNER JOIN models m 33 | ON p.model_id = m.model_id; 34 | ``` 35 | *Pairs ML predictions with their model names.* 36 | 37 | - **Example 2: Join Metrics to Models**: 38 | ```sql 39 | SELECT mm.metric_id, mm.accuracy, m.model_name 40 | FROM model_metrics mm 41 | INNER JOIN models m 42 | ON mm.model_id = m.model_id; 43 | ``` 44 | *Matches ML metrics to model details.* 45 | 46 | - **Example 3: Filter High Scores**: 47 | ```sql 48 | SELECT p.prediction_id, p.score 49 | FROM predictions p 50 | INNER JOIN models m 51 | ON p.model_id = m.model_id 52 | WHERE p.score > 0.9; 53 | ``` 54 | *Gets high-scoring ML predictions with model info.* 55 | 56 | --- 57 | 58 | ## 💡 Practice Tips 59 | 60 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test joins. 61 | - **ML Use Case**: `INNER JOIN` aligns ML predictions with metadata, like model names, for clean analysis. 62 | - **Try This**: Create `predictions` and `models`, join them, and check results with `SELECT`. 63 | - **Debug**: Ensure `ON` conditions match—mismatches drop rows. Verify with `SELECT COUNT(*)`. 64 | 65 | --- 66 | 67 | ## 🚀 Next Steps 68 | 69 | - **Deepen Skills**: Explore `Left Join` for unmatched rows or `Aggregations` for summaries. 70 | - **Portfolio Boost**: Add an `INNER JOIN` query to `irohanportfolio.netlify.app`, explaining its ML data role. 71 | - **Challenge**: Join predictions to models for a portfolio ML dataset. 72 | 73 | Match like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/01 Joins/02 Left Join/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master LEFT JOIN - Keep All Your ML Base Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **LEFT JOIN** keeps all rows from the left table, matching right table rows where possible, ideal for including all ML predictions even without model details. It’s your tool for complete datasets. This guide will teach you `LEFT JOIN` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Inclusion**: Learn how `LEFT JOIN` retains all left table rows. 12 | 2. **Study Syntax**: See how to join with `ON` and handle nulls. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Results**: Check for unmatched rows with nulls. 15 | 5. **ML Spin**: Use `LEFT JOIN` to analyze incomplete ML data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT columns 23 | FROM table1 24 | LEFT JOIN table2 25 | ON table1.column = table2.column; 26 | ``` 27 | 28 | - **Example 1: All Predictions**: 29 | ```sql 30 | SELECT p.prediction_id, p.score, m.model_name 31 | FROM predictions p 32 | LEFT JOIN models m 33 | ON p.model_id = m.model_id; 34 | ``` 35 | *Includes all ML predictions, with nulls for missing models.* 36 | 37 | - **Example 2: Metrics with Models**: 38 | ```sql 39 | SELECT mm.metric_id, mm.accuracy, m.model_name 40 | FROM model_metrics mm 41 | LEFT JOIN models m 42 | ON mm.model_id = m.model_id; 43 | ``` 44 | *Keeps all ML metrics, even without model info.* 45 | 46 | - **Example 3: Filter Unmatched**: 47 | ```sql 48 | SELECT p.prediction_id, p.score 49 | FROM predictions p 50 | LEFT JOIN models m 51 | ON p.model_id = m.model_id 52 | WHERE m.model_id IS NULL; 53 | ``` 54 | *Finds ML predictions without linked models.* 55 | 56 | --- 57 | 58 | ## 💡 Practice Tips 59 | 60 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 61 | - **ML Use Case**: `LEFT JOIN` ensures no ML predictions are lost, even if metadata is incomplete. 62 | - **Try This**: Join `predictions` to `models` with `LEFT JOIN`, check for null `model_name`s. 63 | - **Note**: Nulls appear for unmatched rows—use `IS NULL` to find gaps. 64 | 65 | --- 66 | 67 | ## 🚀 Next Steps 68 | 69 | - **Level Up**: Try `Right Join` for opposite behavior or `Inner Join` for matches. 70 | - **Portfolio Win**: Add a `LEFT JOIN` query to `irohanportfolio.netlify.app`, showing ML data inclusion. 71 | - **Challenge**: Find unmatched ML predictions in a portfolio dataset. 72 | 73 | Include like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/01 Joins/03 Right Join/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master RIGHT JOIN - Prioritize Your ML Reference Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **RIGHT JOIN** keeps all rows from the right table, matching left table rows where possible, great for ensuring all ML model details are included, even without predictions. It’s your tool for reference-first queries. This guide will show you `RIGHT JOIN` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand how `RIGHT JOIN` retains all right table rows. 12 | 2. **Learn Syntax**: Study joining with `ON` and null handling. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Verify Results**: Look for nulls in unmatched left table rows. 15 | 5. **ML Angle**: Use `RIGHT JOIN` to analyze all ML models, matched or not. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT columns 23 | FROM table1 24 | RIGHT JOIN table2 25 | ON table1.column = table2.column; 26 | ``` 27 | 28 | - **Example 1: All Models**: 29 | ```sql 30 | SELECT p.prediction_id, p.score, m.model_name 31 | FROM predictions p 32 | RIGHT JOIN models m 33 | ON p.model_id = m.model_id; 34 | ``` 35 | *Includes all ML models, with nulls for missing predictions.* 36 | 37 | - **Example 2: Models with Metrics**: 38 | ```sql 39 | SELECT mm.metric_id, mm.accuracy, m.model_name 40 | FROM model_metrics mm 41 | RIGHT JOIN models m 42 | ON mm.model_id = m.model_id; 43 | ``` 44 | *Keeps all ML models, even without metrics.* 45 | 46 | - **Example 3: Unmatched Models**: 47 | ```sql 48 | SELECT m.model_name 49 | FROM predictions p 50 | RIGHT JOIN models m 51 | ON p.model_id = m.model_id 52 | WHERE p.prediction_id IS NULL; 53 | ``` 54 | *Finds ML models without predictions.* 55 | 56 | --- 57 | 58 | ## 💡 Practice Tips 59 | 60 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 61 | - **ML Use Case**: `RIGHT JOIN` ensures all ML models are analyzed, even unused ones. 62 | - **Try This**: Join `predictions` to `models` with `RIGHT JOIN`, check for null `prediction_id`s. 63 | - **Tip**: `RIGHT JOIN` is like `LEFT JOIN` flipped—use `IS NULL` to spot unmatched rows. 64 | 65 | --- 66 | 67 | ## 🚀 Next Steps 68 | 69 | - **Go Deeper**: Explore `Full Outer Join` for all rows or `Left Join` for left focus. 70 | - **Portfolio Boost**: Add a `RIGHT JOIN` query to `irohanportfolio.netlify.app`, explaining ML model coverage. 71 | - **Challenge**: Identify unused ML models in a portfolio dataset. 72 | 73 | Prioritize like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/01 Joins/04 Full Outer Join/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master FULL OUTER JOIN - Capture All Your ML Data! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **FULL OUTER JOIN** keeps all rows from both tables, matching where possible, ideal for analyzing complete ML datasets, like all predictions and models, matched or not. It’s your tool for total inclusion. This guide will teach you `FULL OUTER JOIN` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Completeness**: Learn how `FULL OUTER JOIN` includes all rows. 12 | 2. **Study Syntax**: See how to join with `ON` and handle nulls. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Check Nulls**: Identify unmatched rows in both tables. 15 | 5. **ML Spin**: Use `FULL OUTER JOIN` for comprehensive ML data insights. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT columns 23 | FROM table1 24 | FULL OUTER JOIN table2 25 | ON table1.column = table2.column; 26 | ``` 27 | 28 | - **Example 1: All Predictions and Models**: 29 | ```sql 30 | SELECT p.prediction_id, p.score, m.model_name 31 | FROM predictions p 32 | FULL OUTER JOIN models m 33 | ON p.model_id = m.model_id; 34 | ``` 35 | *Shows all ML predictions and models, with nulls for mismatches.* 36 | 37 | - **Example 2: Metrics and Models**: 38 | ```sql 39 | SELECT mm.metric_id, mm.accuracy, m.model_name 40 | FROM model_metrics mm 41 | FULL OUTER JOIN models m 42 | ON mm.model_id = m.model_id; 43 | ``` 44 | *Includes all ML metrics and models, matched or not.* 45 | 46 | - **Example 3: Find Mismatches**: 47 | ```sql 48 | SELECT p.prediction_id, m.model_name 49 | FROM predictions p 50 | FULL OUTER JOIN models m 51 | ON p.model_id = m.model_id 52 | WHERE p.prediction_id IS NULL OR m.model_id IS NULL; 53 | ``` 54 | *Spots unpaired ML predictions or models.* 55 | 56 | --- 57 | 58 | ## 💡 Practice Tips 59 | 60 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or MySQL. 61 | - **ML Use Case**: `FULL OUTER JOIN` reveals gaps in ML datasets, like missing model links. 62 | - **Try This**: Join `predictions` to `models` with `FULL OUTER JOIN`, count nulls in both tables. 63 | - **Note**: Not all DBs support `FULL OUTER JOIN` (e.g., MySQL)—test with PostgreSQL. 64 | 65 | --- 66 | 67 | ## 🚀 Next Steps 68 | 69 | - **Level Up**: Compare with `Inner Join` or `Left Join` for partial matches. 70 | - **Portfolio Win**: Add a `FULL OUTER JOIN` query to `irohanportfolio.netlify.app`, showing ML data completeness. 71 | - **Challenge**: Analyze unmatched ML data in a portfolio dataset. 72 | 73 | Capture like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/01 Joins/05 Self-Join/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master SELF-JOIN - Relate Your ML Data to Itself! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Self-Join** joins a table to itself, perfect for hierarchical or comparative ML data, like pairing predictions by model or date. It’s your trick for internal relationships. This guide will teach you `SELF-JOIN` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand how `SELF-JOIN` compares rows within one table. 12 | 2. **Learn Syntax**: Study aliasing for clarity in joins. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Comparisons**: Check paired rows for accuracy. 15 | 5. **ML Angle**: Use `SELF-JOIN` to analyze ML prediction patterns. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT columns 23 | FROM table_name t1 24 | INNER JOIN table_name t2 25 | ON t1.column = t2.column; 26 | ``` 27 | 28 | - **Example 1: Compare Predictions**: 29 | ```sql 30 | SELECT p1.prediction_id, p1.score, p2.score AS compare_score 31 | FROM predictions p1 32 | INNER JOIN predictions p2 33 | ON p1.model_id = p2.model_id 34 | WHERE p1.prediction_id < p2.prediction_id; 35 | ``` 36 | *Compares ML prediction scores for the same model.* 37 | 38 | - **Example 2: Date Proximity**: 39 | ```sql 40 | SELECT p1.prediction_id, p1.prediction_date, p2.prediction_date AS next_date 41 | FROM predictions p1 42 | INNER JOIN predictions p2 43 | ON p1.model_id = p2.model_id 44 | WHERE p2.prediction_date = p1.prediction_date + INTERVAL '1 day'; 45 | ``` 46 | *Finds consecutive ML predictions by date.* 47 | 48 | - **Example 3: Score Gaps**: 49 | ```sql 50 | SELECT p1.prediction_id, p1.score, p2.score 51 | FROM predictions p1 52 | INNER JOIN predictions p2 53 | ON p1.model_id = p2.model_id 54 | WHERE p2.score > p1.score + 0.1; 55 | ``` 56 | *Spots significant ML score improvements.* 57 | 58 | --- 59 | 60 | ## 💡 Practice Tips 61 | 62 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL. 63 | - **ML Use Case**: `SELF-JOIN` uncovers ML trends, like comparing prediction performance. 64 | - **Try This**: Create `predictions`, self-join by `model_id`, and verify paired scores. 65 | - **Tip**: Aliases (e.g., `p1`, `p2`) are critical—without them, queries get messy. 66 | 67 | --- 68 | 69 | ## 🚀 Next Steps 70 | 71 | - **Go Deeper**: Try `Inner Join` for cross-table joins or `Aggregations` for trends. 72 | - **Portfolio Boost**: Add a `SELF-JOIN` query to `irohanportfolio.netlify.app`, explaining ML comparisons. 73 | - **Challenge**: Compare ML predictions by date in a portfolio dataset. 74 | 75 | Relate like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/01 Joins/06 Cross-Join/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master CROSS JOIN - Combine All Your ML Data Pairs! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **Cross Join** pairs every row from two tables, perfect for generating all possible ML feature combinations or testing scenarios. It’s your tool for exhaustive pairing. This guide will teach you `CROSS JOIN` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Pairing**: Learn how `CROSS JOIN` creates all row combinations. 12 | 2. **Study Syntax**: See the simple join without `ON`. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Check Results**: Verify the large result set of pairs. 15 | 5. **ML Spin**: Use `CROSS JOIN` for ML feature engineering or testing. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT columns 23 | FROM table1 24 | CROSS JOIN table2; 25 | ``` 26 | 27 | - **Example 1: Models and Dates**: 28 | ```sql 29 | SELECT m.model_name, p.prediction_date 30 | FROM models m 31 | CROSS JOIN predictions p; 32 | ``` 33 | *Pairs every ML model with every prediction date.* 34 | 35 | - **Example 2: Feature Combinations**: 36 | ```sql 37 | SELECT p1.score AS score1, p2.score AS score2 38 | FROM predictions p1 39 | CROSS JOIN predictions p2; 40 | ``` 41 | *Generates all ML score pairs for feature analysis.* 42 | 43 | - **Example 3: Metrics and Models**: 44 | ```sql 45 | SELECT mm.accuracy, m.model_name 46 | FROM model_metrics mm 47 | CROSS JOIN models m; 48 | ``` 49 | *Combines all ML metrics with all models for testing.* 50 | 51 | --- 52 | 53 | ## 💡 Practice Tips 54 | 55 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 56 | - **ML Use Case**: `CROSS JOIN` creates ML feature sets, like pairing scores for model inputs. 57 | - **Try This**: Cross-join `models` and `predictions`, count rows with `SELECT COUNT(*)`. 58 | - **Note**: Results can explode (n × m rows)—test with small tables first. 59 | 60 | --- 61 | 62 | ## 🚀 Next Steps 63 | 64 | - **Level Up**: Filter `CROSS JOIN` with `WHERE` or try `Inner Join` for matches. 65 | - **Portfolio Win**: Add a `CROSS JOIN` query to `irohanportfolio.netlify.app`, showing ML feature pairing. 66 | - **Challenge**: Create ML feature pairs in a portfolio dataset. 67 | 68 | Combine like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/01 Count/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master COUNT - Track Your ML Data Like a Pro! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **COUNT** function tallies rows or non-null values, perfect for tracking ML predictions or metrics in your datasets. It’s your go-to for quantifying data. This guide will walk you through learning `COUNT` with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how `COUNT` counts rows or values. 12 | 2. **Study the Syntax**: Learn `COUNT(*)` vs. `COUNT(column)`. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL or MySQL. 14 | 4. **Test Counts**: Verify counts with different conditions. 15 | 5. **Apply to ML**: Use `COUNT` to monitor ML dataset sizes or events. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT COUNT(*) FROM table_name [WHERE condition]; 23 | SELECT COUNT(column_name) FROM table_name [WHERE condition]; 24 | ``` 25 | 26 | - **Example 1: Total Predictions**: 27 | ```sql 28 | SELECT COUNT(*) AS total_predictions 29 | FROM predictions; 30 | ``` 31 | *Counts all ML predictions in the table.* 32 | 33 | - **Example 2: High-Score Predictions**: 34 | ```sql 35 | SELECT COUNT(prediction_id) AS high_score_count 36 | FROM predictions 37 | WHERE score >= 0.9; 38 | ``` 39 | *Tallies ML predictions with high scores.* 40 | 41 | - **Example 3: Non-Null Metrics**: 42 | ```sql 43 | SELECT COUNT(accuracy) AS valid_metrics 44 | FROM model_metrics; 45 | ``` 46 | *Counts non-null ML accuracy metrics.* 47 | 48 | --- 49 | 50 | ## 💡 Practice Tips 51 | 52 | - **Tool Up**: Use [SQLFiddle](http://sqlfiddle.com) or a local DB to test counts. 53 | - **ML Use Case**: `COUNT` tracks ML dataset sizes, like the number of predictions for model evaluation. 54 | - **Try This**: Create a `predictions` table with 5 rows, count rows with `score > 0.8`, and verify with `SELECT`. 55 | - **Debug**: `COUNT(*)` includes all rows; `COUNT(column)` skips nulls—check nulls with `SELECT column_name IS NULL`. 56 | 57 | --- 58 | 59 | ## 🚀 Next Steps 60 | 61 | - **Deepen Skills**: Explore `Group By` to count by categories or `Sum` for totals. 62 | - **Portfolio Boost**: Add a `COUNT` query to `irohanportfolio.netlify.app`, explaining its ML tracking role. 63 | - **Challenge**: Count high-performing ML predictions in a portfolio dataset. 64 | 65 | Tally like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/02 Sum/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master SUM - Total Your ML Data with Ease! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **SUM** function adds up numeric values, ideal for summing ML prediction scores or model accuracies. It’s your tool for aggregating quantitative data. This guide will teach you `SUM` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Totals**: Learn how `SUM` aggregates numbers. 12 | 2. **Study Syntax**: See how to apply `SUM` to columns. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Sums**: Check totals with filters. 15 | 5. **ML Spin**: Use `SUM` to analyze ML performance metrics. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT SUM(column_name) FROM table_name [WHERE condition]; 23 | ``` 24 | 25 | - **Example 1: Total Prediction Scores**: 26 | ```sql 27 | SELECT SUM(score) AS total_score 28 | FROM predictions; 29 | ``` 30 | *Sums all ML prediction scores.* 31 | 32 | - **Example 2: High-Score Sum**: 33 | ```sql 34 | SELECT SUM(score) AS high_score_sum 35 | FROM predictions 36 | WHERE score >= 0.9; 37 | ``` 38 | *Totals ML scores for top predictions.* 39 | 40 | - **Example 3: Model Accuracy Sum**: 41 | ```sql 42 | SELECT SUM(accuracy) AS total_accuracy 43 | FROM model_metrics; 44 | ``` 45 | *Adds up ML model accuracy metrics.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 52 | - **ML Use Case**: `SUM` quantifies ML performance, like total scores for model comparison. 53 | - **Try This**: Insert 5 rows into `predictions`, sum `score` for `model_id = 101`, and verify with `SELECT score`. 54 | - **Note**: `SUM` ignores nulls—check for nulls with `SELECT score IS NULL`. 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Level Up**: Try `Avg` for averages or `Group By` for grouped sums. 61 | - **Portfolio Win**: Add a `SUM` query to `irohanportfolio.netlify.app`, showing ML metric totals. 62 | - **Challenge**: Sum ML scores by model in a portfolio dataset. 63 | 64 | Add up like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/02 Sum/README.md: -------------------------------------------------------------------------------- 1 | # 📈 Sum - Totaling Numeric Values 2 | 3 | ## 🌟 Overview 4 | 5 | The **SUM** function in SQL is an aggregate function that **calculates the total** of numeric values in a column, ignoring `NULL` values. It’s ideal for quantifying cumulative metrics like costs, scores, or sizes. 6 | 7 | In AI/ML, `SUM` is used for **aggregating model scores**, calculating dataset sizes, or summing feature values for preprocessing. For freshers, it’s a **common interview topic**, tested in questions about numerical summaries and pipeline analysis. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | SUM(column_name) 15 | ``` 16 | 17 | - **Basic Example**: 18 | ```sql 19 | SELECT SUM(score) 20 | FROM predictions; 21 | ``` 22 | - **With Grouping**: 23 | ```sql 24 | SELECT model_id, SUM(score) 25 | FROM predictions 26 | GROUP BY model_id; 27 | ``` 28 | 29 | --- 30 | 31 | ## 💡 Use Cases in AI/ML 32 | 33 | - **Model Scoring**: Sum `score` in `predictions` for total performance. 34 | - **Feature Aggregation**: Total `revenue` in `orders` for customer features. 35 | - **Pipeline Metrics**: Sum `size` in `training_data` for storage needs. 36 | - **Experiment Analysis**: Aggregate `cost` in `experiments` for budgeting. 37 | - **Error Metrics**: Sum absolute errors for model evaluation. 38 | 39 | --- 40 | 41 | ## 🔑 Key Features 42 | 43 | - **Numeric Only**: Works on numeric columns (e.g., INTEGER, FLOAT). 44 | - **NULL Ignored**: Skips `NULL` values in calculations. 45 | - **Additive**: Accumulates all qualifying values. 46 | - **Groupable**: Pairs with `GROUP BY` for segmented totals. 47 | 48 | --- 49 | 50 | ## ✅ Best Practices 51 | 52 | - **Validate Data**: Ensure column values are numeric to avoid errors. 53 | - **Handle NULLs**: Check for `NULL` prevalence to avoid skewed sums. 54 | - **Use Filters**: Apply `WHERE` to sum relevant rows only. 55 | - **Optimize Grouping**: Index grouped columns for faster sums. 56 | 57 | --- 58 | 59 | ## ⚠️ Common Pitfalls 60 | 61 | - **Non-Numeric Errors**: Applying `SUM` to non-numeric columns fails. 62 | - **NULL Impact**: Excessive `NULLs` reduce the total unexpectedly. 63 | - **Overflow Risk**: Large datasets may exceed numeric limits. 64 | - **Missing Filters**: Summing without `WHERE` includes unwanted values. 65 | 66 | --- 67 | 68 | ## 📝 Additional Notes 69 | 70 | - **Database Variations**: 71 | - MySQL/PostgreSQL/SQL Server: Standard `SUM` behavior. 72 | - Oracle: Supports `SUM` with analytic extensions. 73 | - **Performance**: Fast for small datasets; indexes help with grouping. 74 | - **Casting**: Use `CAST` for non-numeric columns if needed. -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/03 Avg/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master AVG - Find Your ML Data’s Middle Ground! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **AVG** function calculates the average of numeric values, perfect for finding mean ML prediction scores or model accuracies. It’s your key to understanding central tendencies. This guide will show you `AVG` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand how `AVG` computes means. 12 | 2. **Learn Syntax**: Study applying `AVG` to columns. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Verify Averages**: Test with different conditions. 15 | 5. **ML Angle**: Use `AVG` to evaluate ML model performance. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT AVG(column_name) FROM table_name [WHERE condition]; 23 | ``` 24 | 25 | - **Example 1: Average Prediction Score**: 26 | ```sql 27 | SELECT AVG(score) AS avg_score 28 | FROM predictions; 29 | ``` 30 | *Calculates the mean ML prediction score.* 31 | 32 | - **Example 2: Recent Predictions Average**: 33 | ```sql 34 | SELECT AVG(score) AS recent_avg 35 | FROM predictions 36 | WHERE prediction_date >= '2025-04-01'; 37 | ``` 38 | *Averages ML scores for recent predictions.* 39 | 40 | - **Example 3: Model Accuracy Average**: 41 | ```sql 42 | SELECT AVG(accuracy) AS avg_accuracy 43 | FROM model_metrics; 44 | ``` 45 | *Finds the mean ML model accuracy.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 52 | - **ML Use Case**: `AVG` reveals ML performance trends, like average accuracy for model tuning. 53 | - **Try This**: Add 5 rows to `model_metrics`, average `accuracy`, and cross-check with manual math. 54 | - **Tip**: `AVG` skips nulls—use `SELECT accuracy IS NULL` to spot them. 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Go Deeper**: Pair `AVG` with `Group By` or try `Max` for peaks. 61 | - **Portfolio Boost**: Add an `AVG` query to `irohanportfolio.netlify.app`, explaining ML performance analysis. 62 | - **Challenge**: Average ML accuracies by model in a portfolio dataset. 63 | 64 | Balance like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/03 Avg/README.md: -------------------------------------------------------------------------------- 1 | # 📈 Avg - Averaging Numeric Values 2 | 3 | ## 🌟 Overview 4 | 5 | The **AVG** function in SQL is an aggregate function that **calculates the arithmetic mean** of numeric values in a column, ignoring `NULL` values. It’s perfect for finding typical values or central tendencies. 6 | 7 | In AI/ML, `AVG` is critical for **evaluating model performance** (e.g., average accuracy), normalizing features, or analyzing dataset trends. For freshers, it’s a **frequent interview topic**, tested in questions about metrics and data summarization. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | AVG(column_name) 15 | ``` 16 | 17 | - **Basic Example**: 18 | ```sql 19 | SELECT AVG(accuracy) 20 | FROM models; 21 | ``` 22 | - **With Grouping**: 23 | ```sql 24 | SELECT experiment_id, AVG(score) 25 | FROM results 26 | GROUP BY experiment_id; 27 | ``` 28 | 29 | --- 30 | 31 | ## 💡 Use Cases in AI/ML 32 | 33 | - **Model Evaluation**: Average `accuracy` in `models` for performance metrics. 34 | - **Feature Normalization**: Compute mean `feature1` in `training_data` for scaling. 35 | - **User Behavior**: Average `order_value` in `orders` for customer profiling. 36 | - **Experiment Analysis**: Mean `loss` in `predictions` per `model_id`. 37 | - **Pipeline Monitoring**: Average `latency` in `logs` for performance tracking. 38 | 39 | --- 40 | 41 | ## 🔑 Key Features 42 | 43 | - **Mean Calculation**: Divides sum by count of non-null values. 44 | - **NULL Ignored**: Excludes `NULL` values from computation. 45 | - **Numeric Focus**: Applies to numeric columns only. 46 | - **Groupable**: Works with `GROUP BY` for segmented averages. 47 | 48 | --- 49 | 50 | ## ✅ Best Practices 51 | 52 | - **Check Data Types**: Ensure column is numeric to avoid errors. 53 | - **Account for NULLs**: Verify `NULL` impact on averages. 54 | - **Use ROUND**: Round results (e.g., `ROUND(AVG(score), 2)`) for readability. 55 | - **Filter Wisely**: Use `WHERE` to average relevant data only. 56 | 57 | --- 58 | 59 | ## ⚠️ Common Pitfalls 60 | 61 | - **NULL Skew**: High `NULL` counts lower the denominator, skewing results. 62 | - **Non-Numeric Errors**: Applying `AVG` to strings or dates fails. 63 | - **Outlier Impact**: Extreme values distort the mean without filtering. 64 | - **Ungrouped Averages**: Forgetting `GROUP BY` averages all rows. 65 | 66 | --- 67 | 68 | ## 📝 Additional Notes 69 | 70 | - **Database Variations**: 71 | - MySQL/PostgreSQL/SQL Server: Consistent `AVG` syntax. 72 | - Oracle: Supports `AVG` with analytic functions. 73 | - **Precision**: May return FLOAT; use `ROUND` for clarity. 74 | - **Alternative**: Median requires custom logic in most databases. -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/04 Max/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master MAX - Find Your ML Data’s Peak Performers! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **MAX** function identifies the highest value in a column, ideal for spotting top ML prediction scores or model accuracies. It’s your tool for finding peaks. This guide will teach you `MAX` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Peaks**: Learn how `MAX` grabs the largest value. 12 | 2. **Study Syntax**: See how to apply `MAX` to columns. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Highs**: Verify max values with filters. 15 | 5. **ML Spin**: Use `MAX` to highlight ML model strengths. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT MAX(column_name) FROM table_name [WHERE condition]; 23 | ``` 24 | 25 | - **Example 1: Top Prediction Score**: 26 | ```sql 27 | SELECT MAX(score) AS top_score 28 | FROM predictions; 29 | ``` 30 | *Finds the highest ML prediction score.* 31 | 32 | - **Example 2: Recent Top Score**: 33 | ```sql 34 | SELECT MAX(score) AS recent_max 35 | FROM predictions 36 | WHERE prediction_date >= '2025-04-01'; 37 | ``` 38 | *Gets the top ML score for recent predictions.* 39 | 40 | - **Example 3: Best Accuracy**: 41 | ```sql 42 | SELECT MAX(accuracy) AS best_accuracy 43 | FROM model_metrics; 44 | ``` 45 | *Identifies the highest ML model accuracy.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 52 | - **ML Use Case**: `MAX` pinpoints ML outliers, like the best-performing model for deployment. 53 | - **Try This**: Insert 5 rows into `predictions`, find `MAX(score)`, and verify with `SELECT score ORDER BY score DESC`. 54 | - **Note**: `MAX` ignores nulls—check nulls with `SELECT score IS NULL`. 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Level Up**: Try `Min` for lows or `Group By` for grouped maxes. 61 | - **Portfolio Win**: Add a `MAX` query to `irohanportfolio.netlify.app`, showing ML peak performance. 62 | - **Challenge**: Find the top ML score by model in a portfolio dataset. 63 | 64 | Peak like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/04 Max/README.md: -------------------------------------------------------------------------------- 1 | # 📈 Max - Finding the Highest Value 2 | 3 | ## 🌟 Overview 4 | 5 | The **MAX** function in SQL is an aggregate function that **returns the highest value** in a column, ignoring `NULL` values. It’s used to identify peaks or extremes in datasets, such as maximum scores or dates. 6 | 7 | In AI/ML, `MAX` is valuable for **identifying top-performing models**, finding peak feature values, or tracking latest records. For freshers, it’s a **common interview topic**, tested in questions about data extremes and ranking. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | MAX(column_name) 15 | ``` 16 | 17 | - **Basic Example**: 18 | ```sql 19 | SELECT MAX(score) 20 | FROM predictions; 21 | ``` 22 | - **With Grouping**: 23 | ```sql 24 | SELECT model_id, MAX(accuracy) 25 | FROM models 26 | GROUP BY model_id; 27 | ``` 28 | 29 | --- 30 | 31 | ## 💡 Use Cases in AI/ML 32 | 33 | - **Model Selection**: Find highest `accuracy` in `models` for deployment. 34 | - **Feature Analysis**: Identify max `feature1` in `training_data` for scaling. 35 | - **Event Tracking**: Get latest `timestamp` in `logs` for recency. 36 | - **Experiment Results**: Max `score` in `results` per `experiment_id`. 37 | - **Outlier Detection**: Spot peak values in `predictions` for anomalies. 38 | 39 | --- 40 | 41 | ## 🔑 Key Features 42 | 43 | - **Extreme Value**: Returns the single highest value in a column. 44 | - **NULL Ignored**: Skips `NULL` values in calculations. 45 | - **Flexible Types**: Works on numbers, dates, and strings. 46 | - **Groupable**: Pairs with `GROUP BY` for segmented maxima. 47 | 48 | --- 49 | 50 | ## ✅ Best Practices 51 | 52 | - **Validate Types**: Ensure column type supports comparisons. 53 | - **Use Filters**: Apply `WHERE` to focus on relevant maxima. 54 | - **Index Columns**: Optimize grouped `MAX` with indexes. 55 | - **Test Results**: Verify max values align with expectations. 56 | 57 | --- 58 | 59 | ## ⚠️ Common Pitfalls 60 | 61 | - **NULL Results**: Empty or all-`NULL` columns return `NULL`. 62 | - **Misleading Max**: Applying to strings or dates may confuse intent. 63 | - **Ungrouped Errors**: Forgetting `GROUP BY` returns one max for all rows. 64 | - **Outlier Skew**: Extreme values may require filtering. 65 | 66 | --- 67 | 68 | ## 📝 Additional Notes 69 | 70 | - **Database Variations**: 71 | - MySQL/PostgreSQL/SQL Server: Standard `MAX` syntax. 72 | - Oracle: Supports `MAX` with analytic extensions. 73 | - **Performance**: Fast for indexed columns; slower for strings. 74 | - **Pairing**: Use with `MIN` for range analysis. -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/05 Min/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master MIN - Spot Your ML Data’s Lowest Points! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **MIN** function finds the smallest value in a column, great for identifying low ML prediction scores or model accuracies. It’s your tool for detecting lows. This guide will teach you `MIN` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand how `MIN` picks the smallest value. 12 | 2. **Learn Syntax**: Study applying `MIN` to columns. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Verify Lows**: Test min values with conditions. 15 | 5. **ML Angle**: Use `MIN` to find ML model weaknesses. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT MIN(column_name) FROM table_name [WHERE condition]; 23 | ``` 24 | 25 | - **Example 1: Lowest Prediction Score**: 26 | ```sql 27 | SELECT MIN(score) AS lowest_score 28 | FROM predictions; 29 | ``` 30 | *Finds the lowest ML prediction score.* 31 | 32 | - **Example 2: Recent Low Score**: 33 | ```sql 34 | SELECT MIN(score) AS recent_min 35 | FROM predictions 36 | WHERE prediction_date >= '2025-04-01'; 37 | ``` 38 | *Gets the lowest ML score for recent predictions.* 39 | 40 | - **Example 3: Worst Accuracy**: 41 | ```sql 42 | SELECT MIN(accuracy) AS worst_accuracy 43 | FROM model_metrics; 44 | ``` 45 | *Identifies the lowest ML model accuracy.* 46 | 47 | --- 48 | 49 | ## 💡 Practice Tips 50 | 51 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 52 | - **ML Use Case**: `MIN` highlights ML underperformers, like weak models needing retraining. 53 | - **Try This**: Add 5 rows to `model_metrics`, find `MIN(accuracy)`, and check with `SELECT accuracy ORDER BY accuracy ASC`. 54 | - **Tip**: `MIN` skips nulls—use `SELECT accuracy IS NULL` to check. 55 | 56 | --- 57 | 58 | ## 🚀 Next Steps 59 | 60 | - **Go Deeper**: Pair `MIN` with `Max` or `Group By` for grouped mins. 61 | - **Portfolio Boost**: Add a `MIN` query to `irohanportfolio.netlify.app`, explaining ML weakness detection. 62 | - **Challenge**: Find the lowest ML accuracy by model in a portfolio dataset. 63 | 64 | Spot lows like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/05 Min/README.md: -------------------------------------------------------------------------------- 1 | # 📈 Min - Finding the Lowest Value 2 | 3 | ## 🌟 Overview 4 | 5 | The **MIN** function in SQL is an aggregate function that **returns the lowest value** in a column, ignoring `NULL` values. It’s used to identify minimums, such as smallest scores or earliest dates. 6 | 7 | In AI/ML, `MIN` helps **spot underperforming models**, normalize features, or track earliest events. For freshers, it’s a **common interview topic**, tested in questions about data ranges and optimization. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | MIN(column_name) 15 | ``` 16 | 17 | - **Basic Example**: 18 | ```sql 19 | SELECT MIN(loss) 20 | FROM predictions; 21 | ``` 22 | - **With Grouping**: 23 | ```sql 24 | SELECT experiment_id, MIN(score) 25 | FROM results 26 | GROUP BY experiment_id; 27 | ``` 28 | 29 | --- 30 | 31 | ## 💡 Use Cases in AI/ML 32 | 33 | - **Model Evaluation**: Find lowest `loss` in `predictions` for error analysis. 34 | - **Feature Scaling**: Identify min `feature1` in `training_data` for normalization. 35 | - **Event Tracking**: Get earliest `timestamp` in `logs` for timelines. 36 | - **Experiment Analysis**: Min `accuracy` in `models` per `experiment_id`. 37 | - **Anomaly Detection**: Spot low outliers in `features` for cleaning. 38 | 39 | --- 40 | 41 | ## 🔑 Key Features 42 | 43 | - **Lowest Value**: Returns the single smallest value in a column. 44 | - **NULL Ignored**: Excludes `NULL` values from computation. 45 | - **Versatile Types**: Applies to numbers, dates, and strings. 46 | - **Groupable**: Works with `GROUP BY` for segmented minima. 47 | 48 | --- 49 | 50 | ## ✅ Best Practices 51 | 52 | - **Check Types**: Ensure column supports ordering (e.g., numbers, dates). 53 | - **Filter Data**: Use `WHERE` to target relevant minima. 54 | - **Optimize Indexes**: Index columns for grouped `MIN` queries. 55 | - **Validate Output**: Confirm min values make sense in context. 56 | 57 | --- 58 | 59 | ## ⚠️ Common Pitfalls 60 | 61 | - **NULL Output**: All-`NULL` or empty columns return `NULL`. 62 | - **Type Misuse**: Applying to non-comparable types causes errors. 63 | - **Missing Groups**: Omitting `GROUP BY` aggregates all rows. 64 | - **Outlier Issues**: Low extremes may need filtering for relevance. 65 | 66 | --- 67 | 68 | ## 📝 Additional Notes 69 | 70 | - **Database Variations**: 71 | - MySQL/PostgreSQL/SQL Server: Consistent `MIN` syntax. 72 | - Oracle: Supports `MIN` with analytic functions. 73 | - **Performance**: Efficient with indexes; slower for unindexed strings. 74 | - **Pairing**: Combine with `MAX` for range insights. -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/06 Group By/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master GROUP BY - Organize Your ML Data Insights! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **GROUP BY** clause groups rows by values, perfect for summarizing ML predictions or metrics by model or date. It’s your key to structured aggregations. This guide will teach you `GROUP BY` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Grouping**: Learn how `GROUP BY` organizes data for aggregations. 12 | 2. **Study Syntax**: See how to group with aggregates like `COUNT` or `AVG`. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Groups**: Verify grouped results match expectations. 15 | 5. **ML Spin**: Use `GROUP BY` to analyze ML performance by categories. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column_name, AGGREGATE(column) 23 | FROM table_name 24 | GROUP BY column_name; 25 | ``` 26 | 27 | - **Example 1: Predictions by Model**: 28 | ```sql 29 | SELECT model_id, COUNT(*) AS prediction_count 30 | FROM predictions 31 | GROUP BY model_id; 32 | ``` 33 | *Counts ML predictions per model.* 34 | 35 | - **Example 2: Average Score by Date**: 36 | ```sql 37 | SELECT prediction_date, AVG(score) AS avg_score 38 | FROM predictions 39 | GROUP BY prediction_date; 40 | ``` 41 | *Averages ML scores by prediction date.* 42 | 43 | - **Example 3: Metrics by Model**: 44 | ```sql 45 | SELECT model_id, MAX(accuracy) AS max_accuracy 46 | FROM model_metrics 47 | GROUP BY model_id; 48 | ``` 49 | *Finds the highest ML accuracy per model.* 50 | 51 | --- 52 | 53 | ## 💡 Practice Tips 54 | 55 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 56 | - **ML Use Case**: `GROUP BY` summarizes ML data, like model performance across experiments. 57 | - **Try This**: Group `predictions` by `model_id`, count rows, and verify with `SELECT model_id, COUNT(*)`. 58 | - **Note**: Non-grouped columns need aggregates—test with `SELECT model_id, score` (will fail). 59 | 60 | --- 61 | 62 | ## 🚀 Next Steps 63 | 64 | - **Level Up**: Add `Having Clause` to filter groups or try `Count` for basics. 65 | - **Portfolio Win**: Add a `GROUP BY` query to `irohanportfolio.netlify.app`, showing ML data summaries. 66 | - **Challenge**: Group ML metrics by model in a portfolio dataset. 67 | 68 | Organize like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/02 Aggregations/07 Having Clause/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master HAVING Clause - Filter Your ML Data Groups! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **HAVING Clause** filters grouped data, ideal for focusing on ML models with specific performance thresholds, like high average scores. It’s your tool for refined insights. This guide will teach you `HAVING` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand how `HAVING` filters `GROUP BY` results. 12 | 2. **Learn Syntax**: Study combining `HAVING` with aggregates. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Test Filters**: Verify only desired groups appear. 15 | 5. **ML Angle**: Use `HAVING` to spotlight top ML performers. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column_name, AGGREGATE(column) 23 | FROM table_name 24 | GROUP BY column_name 25 | HAVING condition; 26 | ``` 27 | 28 | - **Example 1: High-Count Models**: 29 | ```sql 30 | SELECT model_id, COUNT(*) AS prediction_count 31 | FROM predictions 32 | GROUP BY model_id 33 | HAVING COUNT(*) > 10; 34 | ``` 35 | *Shows ML models with more than 10 predictions.* 36 | 37 | - **Example 2: Top Average Scores**: 38 | ```sql 39 | SELECT model_id, AVG(score) AS avg_score 40 | FROM predictions 41 | GROUP BY model_id 42 | HAVING AVG(score) >= 0.9; 43 | ``` 44 | *Lists ML models with high average prediction scores.* 45 | 46 | - **Example 3: Accurate Models**: 47 | ```sql 48 | SELECT model_id, AVG(accuracy) AS avg_accuracy 49 | FROM model_metrics 50 | GROUP BY model_id 51 | HAVING AVG(accuracy) > 0.85; 52 | ``` 53 | *Filters ML models with strong average accuracy.* 54 | 55 | --- 56 | 57 | ## 💡 Practice Tips 58 | 59 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or MySQL. 60 | - **ML Use Case**: `HAVING` isolates high-performing ML groups, like models with top metrics. 61 | - **Try This**: Group `model_metrics` by `model_id`, filter with `HAVING AVG(accuracy) > 0.8`, and check results. 62 | - **Tip**: `HAVING` works on aggregates; use `WHERE` for row-level filters first. 63 | 64 | --- 65 | 66 | ## 🚀 Next Steps 67 | 68 | - **Go Deeper**: Combine with `Group By` or try `Avg` for more aggregates. 69 | - **Portfolio Boost**: Add a `HAVING` query to `irohanportfolio.netlify.app`, explaining ML group filtering. 70 | - **Challenge**: Filter high-performing ML models in a portfolio dataset. 71 | 72 | Filter like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/03 Set Operations/02 Union All/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master UNION ALL - Stack Your ML Data Fast! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **UNION ALL** operator combines rows from multiple queries, keeping all rows including duplicates, ideal for quick ML dataset merges like prediction logs. It’s your tool for speed and volume. This guide will teach you `UNION ALL` with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Speed**: Learn how `UNION ALL` includes all rows without deduplication. 12 | 2. **Study Syntax**: See how it mirrors `UNION` but runs faster. 13 | 3. **Run Examples**: Try the queries below in a database like MySQL. 14 | 4. **Test Volume**: Check for duplicate rows in results. 15 | 5. **ML Spin**: Use `UNION ALL` to bulk-combine ML data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... 23 | FROM table1 24 | [WHERE condition] 25 | UNION ALL 26 | SELECT column1, column2, ... 27 | FROM table2 28 | [WHERE condition]; 29 | ``` 30 | 31 | - **Example 1: Stack Predictions**: 32 | ```sql 33 | SELECT prediction_id, score, model_name 34 | FROM predictions 35 | UNION ALL 36 | SELECT prediction_id, score, model_name 37 | FROM archive_predictions; 38 | ``` 39 | *Merges all ML predictions, keeping duplicates.* 40 | 41 | - **Example 2: Recent Data Merge**: 42 | ```sql 43 | SELECT prediction_id, score 44 | FROM predictions 45 | WHERE prediction_date >= '2025-04-01' 46 | UNION ALL 47 | SELECT prediction_id, score 48 | FROM archive_predictions 49 | WHERE prediction_date >= '2025-04-01'; 50 | ``` 51 | *Combines recent ML predictions from both tables.* 52 | 53 | - **Example 3: Mixed Metrics**: 54 | ```sql 55 | SELECT model_id, accuracy AS metric 56 | FROM model_metrics 57 | UNION ALL 58 | SELECT model_id, score AS metric 59 | FROM predictions; 60 | ``` 61 | *Stacks ML metrics and scores for raw analysis.* 62 | 63 | --- 64 | 65 | ## 💡 Practice Tips 66 | 67 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL. 68 | - **ML Use Case**: `UNION ALL` speeds up ML data pipelines, like combining logs for training. 69 | - **Try This**: Add duplicate rows to `predictions` and `archive_predictions`, run `UNION ALL`, and count rows with `SELECT COUNT(*)`. 70 | - **Note**: `UNION ALL` is faster than `UNION`—use it when duplicates are okay or expected. 71 | 72 | --- 73 | 74 | ## 🚀 Next Steps 75 | 76 | - **Level Up**: Compare with `Union` or try `Except` for differences. 77 | - **Portfolio Win**: Add a `UNION ALL` query to `irohanportfolio.netlify.app`, showing ML data stacking. 78 | - **Challenge**: Stack ML logs from multiple tables in a portfolio dataset. 79 | 80 | Stack like a boss, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/03 Set Operations/03 Intersect/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master INTERSECT - Find Your ML Data Overlaps! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **INTERSECT** operator returns rows common to multiple queries, perfect for spotting ML predictions shared across datasets, like current and archived logs. It’s your trick for finding overlaps. This guide will teach you `INTERSECT` with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Concept**: Understand how `INTERSECT` keeps only shared rows. 12 | 2. **Learn Syntax**: Study combining queries for common results. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Verify Overlaps**: Check for matching rows in results. 15 | 5. **ML Angle**: Use `INTERSECT` to identify consistent ML data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... 23 | FROM table1 24 | [WHERE condition] 25 | INTERSECT 26 | SELECT column1, column2, ... 27 | FROM table2 28 | [WHERE condition]; 29 | ``` 30 | 31 | - **Example 1: Common Predictions**: 32 | ```sql 33 | SELECT prediction_id, score 34 | FROM predictions 35 | INTERSECT 36 | SELECT prediction_id, score 37 | FROM archive_predictions; 38 | ``` 39 | *Finds ML predictions in both current and archived tables.* 40 | 41 | - **Example 2: Shared High Scores**: 42 | ```sql 43 | SELECT prediction_id, score 44 | FROM predictions 45 | WHERE score >= 0.9 46 | INTERSECT 47 | SELECT prediction_id, score 48 | FROM archive_predictions 49 | WHERE score >= 0.9; 50 | ``` 51 | *Spots high-scoring ML predictions in both datasets.* 52 | 53 | - **Example 3: Common Models**: 54 | ```sql 55 | SELECT model_id 56 | FROM predictions 57 | INTERSECT 58 | SELECT model_id 59 | FROM model_metrics; 60 | ``` 61 | *Identifies ML models with both predictions and metrics.* 62 | 63 | --- 64 | 65 | ## 💡 Practice Tips 66 | 67 | - **Get Hands-On**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL (MySQL lacks `INTERSECT`). 68 | - **ML Use Case**: `INTERSECT` validates ML data consistency, like matching predictions across sources. 69 | - **Try This**: Create `predictions` and `archive_predictions` with shared rows, run `INTERSECT`, and verify with `SELECT`. 70 | - **Tip**: Ensure queries have identical columns—mismatches break `INTERSECT`. 71 | 72 | --- 73 | 74 | ## 🚀 Next Steps 75 | 76 | - **Go Deeper**: Try `Except` for unique rows or `Union` for merges. 77 | - **Portfolio Boost**: Add an `INTERSECT` query to `irohanportfolio.netlify.app`, explaining ML data overlap. 78 | - **Challenge**: Find common ML predictions in a portfolio dataset. 79 | 80 | Overlap like a pro, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/03 Set Operations/03 Intersect/README.md: -------------------------------------------------------------------------------- 1 | # 🔄 Intersect - Finding Common Rows 2 | 3 | ## 🌟 Overview 4 | 5 | The **INTERSECT** operator in SQL returns **rows common to two or more `SELECT` queries**, effectively identifying the overlap between result sets. It automatically removes duplicates, acting like a set intersection. 6 | 7 | In AI/ML, `INTERSECT` is useful for **finding shared records**, such as common users across datasets or matching predictions between models. For freshers, it’s an **advanced interview topic**, tested in questions about data reconciliation and overlap analysis. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | SELECT column(s) FROM table1 15 | INTERSECT 16 | SELECT column(s) FROM table2; 17 | ``` 18 | 19 | - **Basic Example**: 20 | ```sql 21 | SELECT user_id FROM training_data_2023 22 | INTERSECT 23 | SELECT user_id FROM training_data_2024; 24 | ``` 25 | - **With Multiple Columns**: 26 | ```sql 27 | SELECT model_id, name FROM models_v1 28 | INTERSECT 29 | SELECT model_id, name FROM models_v2; 30 | ``` 31 | 32 | --- 33 | 34 | ## 💡 Use Cases in AI/ML 35 | 36 | - **Data Overlap**: Identify `user_id` present in both `orders` and `reviews`. 37 | - **Model Consistency**: Find `predictions` matching across `model_id` runs. 38 | - **Dataset Validation**: Confirm `training_data` shared between sources. 39 | - **Experiment Analysis**: Locate `results` common to multiple `experiments`. 40 | - **Quality Control**: Verify `features` consistent across pipelines. 41 | 42 | --- 43 | 44 | ## 🔑 Key Features 45 | 46 | - **Common Rows**: Returns only rows appearing in all queries. 47 | - **Deduplication**: Removes duplicates within the result set. 48 | - **Column Matching**: Requires identical column counts and types. 49 | - **Set-Based**: Focuses on exact row matches. 50 | 51 | --- 52 | 53 | ## ✅ Best Practices 54 | 55 | - **Align Columns**: Ensure queries have matching columns and types. 56 | - **Reduce Rows**: Filter with `WHERE` before `INTERSECT` for efficiency. 57 | - **Test Small**: Verify overlaps with small datasets to confirm logic. 58 | - **Check Support**: Confirm database supports `INTERSECT` (e.g., not MySQL). 59 | 60 | --- 61 | 62 | ## ⚠️ Common Pitfalls 63 | 64 | - **Unsupported Databases**: MySQL lacks `INTERSECT`; requires workarounds. 65 | - **Column Mismatch**: Incompatible columns cause errors. 66 | - **Empty Results**: No overlapping rows return nothing. 67 | - **Performance Cost**: Large datasets slow `INTERSECT` without optimization. 68 | 69 | --- 70 | 71 | ## 📝 Additional Notes 72 | 73 | - **Database Variations**: 74 | - MySQL: No `INTERSECT`; emulate with `INNER JOIN` or subqueries. 75 | - PostgreSQL/SQL Server: Full `INTERSECT` support. 76 | - Oracle: Supports `INTERSECT` with consistent behavior. 77 | - **Performance**: Can be slower than joins; indexes help. 78 | - **Workaround**: Use `IN` or joins for MySQL compatibility. -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/03 Set Operations/04 Except/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master EXCEPT - Spot Your ML Data Differences! 2 | 3 | ## 🌟 Welcome 4 | 5 | The **EXCEPT** operator returns rows unique to the first query, great for finding ML predictions in one dataset but not another, like new vs. archived logs. It’s your tool for spotting differences. This guide will teach you `EXCEPT` with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Uniqueness**: Learn how `EXCEPT` keeps only first-query rows. 12 | 2. **Study Syntax**: See how to compare queries for differences. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Test Differences**: Verify only unique rows remain. 15 | 5. **ML Spin**: Use `EXCEPT` to identify new or missing ML data. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column1, column2, ... 23 | FROM table1 24 | [WHERE condition] 25 | EXCEPT 26 | SELECT column1, column2, ... 27 | FROM table2 28 | [WHERE condition]; 29 | ``` 30 | 31 | - **Example 1: New Predictions**: 32 | ```sql 33 | SELECT prediction_id, score 34 | FROM predictions 35 | EXCEPT 36 | SELECT prediction_id, score 37 | FROM archive_predictions; 38 | ``` 39 | *Finds ML predictions only in the current table.* 40 | 41 | - **Example 2: Unique High Scores**: 42 | ```sql 43 | SELECT prediction_id, score 44 | FROM predictions 45 | WHERE score >= 0.9 46 | EXCEPT 47 | SELECT prediction_id, score 48 | FROM archive_predictions 49 | WHERE score >= 0.9; 50 | ``` 51 | *Spots high-scoring ML predictions not in archives.* 52 | 53 | - **Example 3: Unlogged Models**: 54 | ```sql 55 | SELECT model_id 56 | FROM predictions 57 | EXCEPT 58 | SELECT model_id 59 | FROM model_metrics; 60 | ``` 61 | *Identifies ML models with predictions but no metrics.* 62 | 63 | --- 64 | 65 | ## 💡 Practice Tips 66 | 67 | - **Tool Time**: Practice on [DB Fiddle](https://www.db-fiddle.com) or PostgreSQL (MySQL lacks `EXCEPT`). 68 | - **ML Use Case**: `EXCEPT` highlights new ML data, like predictions not yet archived. 69 | - **Try This**: Add unique rows to `predictions`, run `EXCEPT` with `archive_predictions`, and check results. 70 | - **Note**: Column types must match—use `SELECT` to test each query separately first. 71 | 72 | --- 73 | 74 | ## 🚀 Next Steps 75 | 76 | - **Level Up**: Compare with `Intersect` for overlaps or `Union All` for merges. 77 | - **Portfolio Win**: Add an `EXCEPT` query to `irohanportfolio.netlify.app`, showing ML data differences. 78 | - **Challenge**: Find unique ML predictions in a portfolio dataset. 79 | 80 | Differentiate like a boss, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/06 Joins and Aggregations/03 Set Operations/04 Except/README.md: -------------------------------------------------------------------------------- 1 | # 🔄 Except - Finding Unique Rows 2 | 3 | ## 🌟 Overview 4 | 5 | The **EXCEPT** operator in SQL returns **rows from the first `SELECT` query that are not present in the second**, effectively identifying differences. It removes duplicates, acting like a set difference. 6 | 7 | In AI/ML, `EXCEPT` is valuable for **isolating unique records**, such as users in one dataset but not another or missing predictions. For freshers, it’s an **advanced interview topic**, tested in questions about data comparison and cleaning. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | SELECT column(s) FROM table1 15 | EXCEPT 16 | SELECT column(s) FROM table2; 17 | ``` 18 | 19 | - **Basic Example**: 20 | ```sql 21 | SELECT user_id FROM training_data_2023 22 | EXCEPT 23 | SELECT user_id FROM training_data_2024; 24 | ``` 25 | - **With Multiple Columns**: 26 | ```sql 27 | SELECT model_id, name FROM models_v1 28 | EXCEPT 29 | SELECT model_id, name FROM models_v2; 30 | ``` 31 | 32 | --- 33 | 34 | ## 💡 Use Cases in AI/ML 35 | 36 | - **Data Diffing**: Find `user_id` in `orders` but not `reviews`. 37 | - **Model Gaps**: Identify `predictions` missing in one `model_id` run. 38 | - **Dataset Cleaning**: Isolate `training_data` unique to one source. 39 | - **Experiment Analysis**: Spot `results` exclusive to an `experiment`. 40 | - **Pipeline Validation**: Detect `logs` absent in a secondary table. 41 | 42 | --- 43 | 44 | ## 🔑 Key Features 45 | 46 | - **Difference Operation**: Returns rows in the first query not in the second. 47 | - **Deduplication**: Removes duplicates from the result. 48 | - **Column Matching**: Requires identical column counts and types. 49 | - **Directional**: Order of queries matters (first minus second). 50 | 51 | --- 52 | 53 | ## ✅ Best Practices 54 | 55 | - **Ensure Column Match**: Verify queries have identical columns and types. 56 | - **Filter First**: Use `WHERE` to reduce rows before `EXCEPT`. 57 | - **Test Differences**: Check small datasets to confirm unique rows. 58 | - **Verify Support**: Confirm `EXCEPT` availability (e.g., not MySQL). 59 | 60 | --- 61 | 62 | ## ⚠️ Common Pitfalls 63 | 64 | - **No MySQL Support**: `EXCEPT` unavailable; requires subquery workarounds. 65 | - **Column Errors**: Mismatched columns break the query. 66 | - **Empty Output**: Overlapping data may return no rows. 67 | - **Performance Issues**: Large datasets slow `EXCEPT` without indexes. 68 | 69 | --- 70 | 71 | ## 📝 Additional Notes 72 | 73 | - **Database Variations**: 74 | - MySQL: No `EXCEPT`; use `NOT IN` or `LEFT JOIN` with `NULL`. 75 | - PostgreSQL/SQL Server: Full `EXCEPT` support (SQL Server uses `EXCEPT`). 76 | - Oracle: Supports `MINUS` instead of `EXCEPT`. 77 | - **Performance**: Indexes on compared columns improve speed. 78 | - **Alternative**: Joins or subqueries for MySQL compatibility. -------------------------------------------------------------------------------- /SQL Fundamentals/07 Stored Procedures/03 Calling Procedures/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Calling Stored Procedures - Run Your ML Automation! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Calling Stored Procedures** executes your saved SQL logic, like running ML data summaries or filtered queries. It’s your way to trigger automation. This guide will show you how to call procedures with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand how to invoke procedures with `CALL`. 12 | 2. **Learn Syntax**: Study calling with or without parameters. 13 | 3. **Run Examples**: Try the calls below in a database like PostgreSQL. 14 | 4. **Test Outputs**: Verify procedure results match expectations. 15 | 5. **ML Angle**: Use calls to automate ML data tasks. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | CALL procedure_name([parameter1, parameter2, ...]); 23 | ``` 24 | 25 | - **Example 1: Simple Call**: 26 | ```sql 27 | -- Assume procedure: GetPredictionCount 28 | CALL GetPredictionCount(); 29 | ``` 30 | *Runs a procedure to count ML predictions.* 31 | 32 | - **Example 2: Parameter Call**: 33 | ```sql 34 | -- Assume procedure: GetPredictionsByModel(IN modelId INT) 35 | CALL GetPredictionsByModel(101); 36 | ``` 37 | *Fetches ML predictions for model ID 101.* 38 | 39 | - **Example 3: Output Parameter**: 40 | ```sql 41 | -- Assume procedure: CountHighScores(IN minScore FLOAT, OUT total INT) 42 | SET @total = 0; 43 | CALL CountHighScores(0.9, @total); 44 | SELECT @total AS high_score_count; 45 | ``` 46 | *Gets the count of high-scoring ML predictions.* 47 | 48 | --- 49 | 50 | ## 💡 Practice Tips 51 | 52 | - **Get Hands-On**: Use MySQL Workbench or [SQLFiddle](http://sqlfiddle.com) to call procedures. 53 | - **ML Use Case**: Calling procedures automates ML workflows, like generating model reports. 54 | - **Try This**: Create a procedure to list predictions, call it, and verify with a manual `SELECT`. 55 | - **Tip**: For `OUT` parameters, use session variables (e.g., `@total`) and `SELECT` to view results. 56 | 57 | --- 58 | 59 | ## 🚀 Next Steps 60 | 61 | - **Go Deeper**: Explore `Parameters` for dynamic calls or `Dropping Procedures` to clean up. 62 | - **Portfolio Boost**: Add a `CALL` example to `irohanportfolio.netlify.app`, explaining ML automation. 63 | - **Challenge**: Call a procedure to summarize ML data in a portfolio dataset. 64 | 65 | Execute like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/07 Stored Procedures/04 Dropping Procedures/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Dropping Stored Procedures - Clean Up Your ML Database! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Dropping Stored Procedures** removes outdated or unused SQL logic, like old ML data scripts, keeping your database tidy. It’s your tool for maintenance. This guide will teach you dropping procedures with ML-themed examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Cleanup**: Learn why and when to drop procedures. 12 | 2. **Study Syntax**: See the `DROP PROCEDURE` command. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Verify Removal**: Confirm procedures are gone. 15 | 5. **ML Spin**: Use dropping to manage ML procedure lifecycles. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | DROP PROCEDURE [IF EXISTS] procedure_name; 23 | ``` 24 | 25 | - **Example 1: Drop Count Procedure**: 26 | ```sql 27 | DROP PROCEDURE IF EXISTS GetPredictionCount; 28 | ``` 29 | *Removes a procedure counting ML predictions.* 30 | 31 | - **Example 2: Drop Summary Procedure**: 32 | ```sql 33 | DROP PROCEDURE IF EXISTS SummarizeHighScores; 34 | ``` 35 | *Deletes a procedure summarizing ML high scores.* 36 | 37 | - **Example 3: Safe Drop**: 38 | ```sql 39 | DROP PROCEDURE IF EXISTS GetRecentPredictions; 40 | ``` 41 | *Safely drops a procedure for recent ML predictions, avoiding errors if it doesn’t exist.* 42 | 43 | --- 44 | 45 | ## 💡 Practice Tips 46 | 47 | - **Tool Time**: Use [DBeaver](https://dbeaver.io) or pgAdmin to drop procedures. 48 | - **ML Use Case**: Dropping procedures clears outdated ML scripts, like old data prep routines. 49 | - **Try This**: Create a dummy procedure, drop it, and check with `SHOW PROCEDURE STATUS` (MySQL) or `SELECT * FROM information_schema.routines`. 50 | - **Note**: Use `IF EXISTS` to prevent errors—trying to drop a non-existent procedure fails otherwise. 51 | 52 | --- 53 | 54 | ## 🚀 Next Steps 55 | 56 | - **Level Up**: Revisit `Creating Procedures` to rebuild or `Calling Procedures` for usage. 57 | - **Portfolio Win**: Add a `DROP PROCEDURE` example to `irohanportfolio.netlify.app`, showing ML database maintenance. 58 | - **Challenge**: Drop an outdated ML procedure in a portfolio dataset. 59 | 60 | Clean up like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/07 Stored Procedures/04 Dropping Procedures/README.md: -------------------------------------------------------------------------------- 1 | # 🛠️ Dropping Procedures - Cleaning Up Logic 2 | 3 | ## 🌟 Overview 4 | 5 | **Dropping Stored Procedures** removes a procedure from the database, freeing resources and preventing obsolete logic from being executed. It’s a Data Definition Language (DDL) operation used during maintenance or cleanup. 6 | 7 | In AI/ML, dropping procedures helps **manage pipeline updates**, like removing outdated preprocessing scripts. For freshers, it’s a **niche interview topic**, often tested in questions about database administration and lifecycle management. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | -- Generic SQL (varies by database) 15 | DROP PROCEDURE [IF EXISTS] procedure_name; 16 | ``` 17 | 18 | - **Basic Example** (MySQL syntax): 19 | ```sql 20 | DROP PROCEDURE IF EXISTS CleanTrainingData; 21 | ``` 22 | - **SQL Server Example**: 23 | ```sql 24 | DROP PROCEDURE GetPredictionCount; 25 | ``` 26 | 27 | --- 28 | 29 | ## 💡 Use Cases in AI/ML 30 | 31 | - **Pipeline Cleanup**: Drop old `CleanTrainingData` after updating logic. 32 | - **Model Retirement**: Remove `ScoreTestData` for deprecated models. 33 | - **Experiment Refresh**: Delete `LogExperiment` for revised workflows. 34 | - **Resource Management**: Free space by dropping unused `UpdateFeatureTable`. 35 | - **Security Updates**: Remove `TrackResults` to enforce new access rules. 36 | 37 | --- 38 | 39 | ## 🔑 Key Features 40 | 41 | - **Permanent Removal**: Deletes the procedure entirely. 42 | - **Conditional Drop**: `IF EXISTS` prevents errors for non-existent procedures. 43 | - **Schema-Specific**: Targets procedures in a specific database or schema. 44 | - **Irreversible**: Requires recreation to restore. 45 | 46 | --- 47 | 48 | ## ✅ Best Practices 49 | 50 | - **Use IF EXISTS**: Prevent errors when procedures don’t exist. 51 | - **Verify Usage**: Ensure procedure is obsolete before dropping. 52 | - **Backup Logic**: Save procedure code before deletion. 53 | - **Check Permissions**: Confirm `DROP` privileges for the schema. 54 | 55 | --- 56 | 57 | ## ⚠️ Common Pitfalls 58 | 59 | - **Accidental Deletion**: Dropping active procedures disrupts workflows. 60 | - **No Backup**: Losing logic without saving makes recovery hard. 61 | - **Permission Errors**: Lack of privileges blocks dropping. 62 | - **Name Mistakes**: Incorrect names cause silent failures without `IF EXISTS`. 63 | 64 | --- 65 | 66 | ## 📝 Additional Notes 67 | 68 | - **Database Variations**: 69 | - **MySQL**: Supports `DROP PROCEDURE [IF EXISTS]`. 70 | - **PostgreSQL**: Uses `DROP PROCEDURE [IF EXISTS]`; may require schema. 71 | - **SQL Server**: Supports `DROP PROCEDURE`; no `IF EXISTS` in older versions. 72 | - **Oracle**: Uses `DROP PROCEDURE` with optional schema prefix. 73 | - **Dependencies**: Check for dependent objects (e.g., triggers) before dropping. 74 | - **Auditing**: Log drops for tracking database changes. -------------------------------------------------------------------------------- /SQL Fundamentals/08 Triggers/04 Dropping Triggers/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Dropping Triggers - Tidy Up Your ML Database! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Dropping Triggers** removes outdated or unused database automation, like old ML logging scripts, keeping your database clean. It’s your tool for maintenance. This guide will teach you dropping triggers with ML-themed examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Cleanup**: Learn why and when to drop triggers. 12 | 2. **Study Syntax**: See the `DROP TRIGGER` command. 13 | 3. **Run Examples**: Try the commands below in a database like MySQL. 14 | 4. **Verify Removal**: Confirm triggers are gone. 15 | 5. **ML Spin**: Use dropping to manage ML trigger lifecycles. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | DROP TRIGGER [IF EXISTS] trigger_name; 23 | ``` 24 | 25 | - **Example 1: Drop Log Trigger**: 26 | ```sql 27 | DROP TRIGGER IF EXISTS log_new_prediction; 28 | ``` 29 | *Removes a trigger logging ML predictions.* 30 | 31 | - **Example 2: Drop Validation Trigger**: 32 | ```sql 33 | DROP TRIGGER IF EXISTS check_score; 34 | ``` 35 | *Deletes a trigger validating ML scores.* 36 | 37 | - **Example 3: Safe Drop**: 38 | ```sql 39 | DROP TRIGGER IF EXISTS log_score_update; 40 | ``` 41 | *Safely drops a trigger for ML score changes, avoiding errors.* 42 | 43 | --- 44 | 45 | ## 💡 Practice Tips 46 | 47 | - **Tool Time**: Use [DBeaver](https://dbeaver.io) or pgAdmin to drop triggers. 48 | - **ML Use Case**: Dropping triggers clears outdated ML automation, like old validation rules. 49 | - **Try This**: Create a dummy trigger, drop it, and check with `SHOW TRIGGERS` (MySQL) or `SELECT * FROM information_schema.triggers`. 50 | - **Note**: Use `IF EXISTS` to avoid errors—dropping non-existent triggers fails otherwise. 51 | 52 | --- 53 | 54 | ## 🚀 Next Steps 55 | 56 | - **Level Up**: Revisit `Creating Triggers` to rebuild or `AFTER Triggers` for logging. 57 | - **Portfolio Win**: Add a `DROP TRIGGER` example to `irohanportfolio.netlify.app`, showing ML database maintenance. 58 | - **Challenge**: Drop an outdated ML trigger in a portfolio dataset. 59 | 60 | Clean up like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/08 Triggers/04 Dropping Triggers/README.md: -------------------------------------------------------------------------------- 1 | # ⚡ Dropping Triggers - Removing Event Automation 2 | 3 | ## 🌟 Overview 4 | 5 | **Dropping Triggers** removes a trigger from the database, stopping its automatic execution for associated events. It’s a Data Definition Language (DDL) operation used during maintenance, cleanup, or when trigger logic becomes obsolete. 6 | 7 | In AI/ML, dropping triggers helps **update pipelines**, like removing outdated validation rules or logging triggers. For freshers, it’s a **niche interview topic**, often tested in questions about database administration and lifecycle management. 8 | 9 | --- 10 | 11 | ## 📜 Syntax 12 | 13 | ```sql 14 | -- Generic SQL (varies by database) 15 | DROP TRIGGER [IF EXISTS] trigger_name 16 | [ON table_name]; 17 | ``` 18 | 19 | - **Basic Example** (MySQL syntax): 20 | ```sql 21 | DROP TRIGGER IF EXISTS LogNewPrediction; 22 | ``` 23 | - **SQL Server Example**: 24 | ```sql 25 | DROP TRIGGER UpdateExperimentStatus; 26 | ``` 27 | 28 | --- 29 | 30 | ## 💡 Use Cases in AI/ML 31 | 32 | - **Pipeline Refresh**: Drop `ValidateTrainingData` after revising logic. 33 | - **Logging Cleanup**: Remove `LogPredictionInsert` for deprecated audits. 34 | - **Model Updates**: Delete `CheckModelAccuracy` for new validation rules. 35 | - **Resource Optimization**: Drop unused `UpdateExperimentStatus` to free resources. 36 | - **Security Revamp**: Remove `LogFeatureUpdate` to align with new policies. 37 | 38 | --- 39 | 40 | ## 🔑 Key Features 41 | 42 | - **Permanent Removal**: Deletes the trigger entirely. 43 | - **Conditional Drop**: `IF EXISTS` avoids errors for non-existent triggers. 44 | - **Table-Specific**: Targets triggers tied to a specific table. 45 | - **Non-Recoverable**: Requires recreation to restore. 46 | 47 | --- 48 | 49 | ## ✅ Best Practices 50 | 51 | - **Use IF EXISTS**: Prevent errors for missing triggers (where supported). 52 | - **Confirm Obsolescence**: Verify trigger is no longer needed. 53 | - **Backup Logic**: Save trigger code before dropping. 54 | - **Check Permissions**: Ensure `DROP TRIGGER` privileges. 55 | 56 | --- 57 | 58 | ## ⚠️ Common Pitfalls 59 | 60 | - **Workflow Disruption**: Dropping active triggers breaks automation. 61 | - **No Backup**: Losing trigger logic complicates recovery. 62 | - **Permission Errors**: Insufficient privileges prevent dropping. 63 | - **Name Errors**: Incorrect trigger names fail silently without `IF EXISTS`. 64 | 65 | --- 66 | 67 | ## 📝 Additional Notes 68 | 69 | - **Database Variations**: 70 | - **MySQL**: Supports `DROP TRIGGER [IF EXISTS]`; table-specific. 71 | - **PostgreSQL**: Uses `DROP TRIGGER [IF EXISTS] trigger_name ON table_name`. 72 | - **SQL Server**: Supports `DROP TRIGGER`; no `IF EXISTS` in older versions. 73 | - **Oracle**: Uses `DROP TRIGGER trigger_name`. 74 | - **Dependencies**: Ensure no dependent processes rely on the trigger. 75 | - **Auditing**: Log drops for database change tracking. -------------------------------------------------------------------------------- /SQL Fundamentals/10 Indexing/01 Creating Indexes/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Creating Indexes - Turbocharge Your ML Queries! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Creating Indexes** boosts database performance by speeding up ML data lookups, like finding predictions by model or date. It’s your key to lightning-fast queries. This guide will walk you through learning to create indexes with ML-themed examples, powering up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Grasp the Basics**: Understand how indexes accelerate searches. 12 | 2. **Study the Syntax**: Learn the `CREATE INDEX` command. 13 | 3. **Run Examples**: Try the indexes below in a database like MySQL or PostgreSQL. 14 | 4. **Test Speed**: Compare query times with and without indexes. 15 | 5. **Apply to ML**: Use indexes to optimize ML data retrieval. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | CREATE INDEX index_name ON table_name (column_name); 23 | CREATE UNIQUE INDEX index_name ON table_name (column_name); 24 | ``` 25 | 26 | - **Example 1: Index on Model ID**: 27 | ```sql 28 | CREATE INDEX idx_model_id ON predictions (model_id); 29 | ``` 30 | *Speeds up ML queries filtering by model ID.* 31 | 32 | - **Example 2: Index on Prediction Date**: 33 | ```sql 34 | CREATE INDEX idx_prediction_date ON predictions (prediction_date); 35 | ``` 36 | *Boosts ML queries for date-based prediction lookups.* 37 | 38 | - **Example 3: Unique Index on Prediction ID**: 39 | ```sql 40 | CREATE UNIQUE INDEX idx_prediction_id ON predictions (prediction_id); 41 | ``` 42 | *Ensures unique ML prediction IDs with fast access.* 43 | 44 | --- 45 | 46 | ## 💡 Practice Tips 47 | 48 | - **Tool Up**: Use MySQL Workbench or [DBeaver](https://dbeaver.io) to create indexes. 49 | - **ML Use Case**: Indexes optimize ML pipelines, like fetching predictions for model evaluation. 50 | - **Try This**: Create `idx_model_id`, run `SELECT * FROM predictions WHERE model_id = 101`, and compare speed with `EXPLAIN`. 51 | - **Debug**: Check indexes with `SHOW INDEX FROM predictions`—avoid indexing small tables. 52 | 53 | --- 54 | 55 | ## 🚀 Next Steps 56 | 57 | - **Deepen Skills**: Explore `B-Tree Indexes` for structure or `Specialty Indexes` for unique cases. 58 | - **Portfolio Boost**: Add an index example to `irohanportfolio.netlify.app`, explaining its ML speedup. 59 | - **Challenge**: Index a column for fast ML queries in a portfolio dataset. 60 | 61 | Speed up like a champ, and let’s make your SQL skills sparkle! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/10 Indexing/02 B-Tree Indexes/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master B-Tree Indexes - Balance Your ML Query Power! 2 | 3 | ## 🌟 Welcome 4 | 5 | **B-Tree Indexes** organize data in a balanced tree, perfect for speeding up ML queries with ranges or sorting, like finding predictions by score or date. They’re your go-to for versatile performance. This guide will teach you B-Tree indexes with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Structure**: Learn how B-Tree indexes handle ranges and equality. 12 | 2. **Study Syntax**: See how to create B-Tree indexes (default in most DBs). 13 | 3. **Run Examples**: Try the indexes below in a database like PostgreSQL. 14 | 4. **Test Efficiency**: Query with ranges and check performance. 15 | 5. **ML Spin**: Use B-Tree for ML data lookups and aggregations. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | CREATE INDEX index_name ON table_name USING BTREE (column_name); 23 | ``` 24 | 25 | - **Example 1: B-Tree on Score**: 26 | ```sql 27 | CREATE INDEX idx_score_btree ON predictions USING BTREE (score); 28 | ``` 29 | *Speeds up ML queries for score ranges (e.g., `score > 0.9`).* 30 | 31 | - **Example 2: B-Tree on Date**: 32 | ```sql 33 | CREATE INDEX idx_date_btree ON predictions USING BTREE (prediction_date); 34 | ``` 35 | *Boosts ML queries for date ranges or sorting.* 36 | 37 | - **Example 3: Composite B-Tree**: 38 | ```sql 39 | CREATE INDEX idx_model_date_btree ON predictions USING BTREE (model_id, prediction_date); 40 | ``` 41 | *Optimizes ML queries combining model and date filters.* 42 | 43 | --- 44 | 45 | ## 💡 Practice Tips 46 | 47 | - **Tool Time**: Use [pgAdmin](https://www.pgadmin.org) or MySQL Workbench to test B-Trees. 48 | - **ML Use Case**: B-Tree indexes shine in ML for range queries, like analyzing prediction trends. 49 | - **Try This**: Create `idx_score_btree`, run `SELECT * FROM predictions WHERE score BETWEEN 0.8 AND 1`, and use `EXPLAIN` to see index usage. 50 | - **Note**: B-Trees are default in MySQL—omit `USING BTREE` there. 51 | 52 | --- 53 | 54 | ## 🚀 Next Steps 55 | 56 | - **Level Up**: Try `Hash Indexes` for equality or `Creating Indexes` for basics. 57 | - **Portfolio Win**: Add a B-Tree example to `irohanportfolio.netlify.app`, showing ML query optimization. 58 | - **Challenge**: Create a B-Tree index for ML range queries in a portfolio dataset. 59 | 60 | Balance like a pro, and let’s rock your SQL journey! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/10 Indexing/03 Hash Indexes/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Hash Indexes - Zip Through ML Equality Queries! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Hash Indexes** use a hash table for super-fast equality lookups, ideal for ML queries matching exact values, like finding predictions by model ID. They’re your speed boost for precise searches. This guide will show you hash indexes with ML examples, boosting your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Get the Idea**: Understand how hash indexes optimize equality checks. 12 | 2. **Learn Syntax**: Study creating hash indexes (supported in PostgreSQL). 13 | 3. **Run Examples**: Try the indexes below in a database like PostgreSQL. 14 | 4. **Test Speed**: Run exact-match queries and compare times. 15 | 5. **ML Angle**: Use hash indexes for ML key-based lookups. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | CREATE INDEX index_name ON table_name USING HASH (column_name); 23 | ``` 24 | 25 | - **Example 1: Hash on Model ID**: 26 | ```sql 27 | CREATE INDEX idx_model_hash ON predictions USING HASH (model_id); 28 | ``` 29 | *Speeds up ML queries for exact model IDs.* 30 | 31 | - **Example 2: Hash on Model Name**: 32 | ```sql 33 | CREATE INDEX idx_model_name_hash ON predictions USING HASH (model_name); 34 | ``` 35 | *Boosts ML queries matching specific model names.* 36 | 37 | - **Example 3: Hash on Prediction ID**: 38 | ```sql 39 | CREATE INDEX idx_pred_id_hash ON predictions USING HASH (prediction_id); 40 | ``` 41 | *Optimizes ML queries for exact prediction IDs.* 42 | 43 | --- 44 | 45 | ## 💡 Practice Tips 46 | 47 | - **Get Hands-On**: Use [DBeaver](https://dbeaver.io) or PostgreSQL (MySQL doesn’t support hash indexes). 48 | - **ML Use Case**: Hash indexes excel in ML for key lookups, like fetching specific model data. 49 | - **Try This**: Create `idx_model_hash`, run `SELECT * FROM predictions WHERE model_id = 101`, and check `EXPLAIN` for index use. 50 | - **Tip**: Hash indexes don’t support ranges—use B-Tree for `>` or `<`. 51 | 52 | --- 53 | 54 | ## 🚀 Next Steps 55 | 56 | - **Go Deeper**: Explore `B-Tree Indexes` for ranges or `Specialty Indexes` for unique needs. 57 | - **Portfolio Boost**: Add a hash index example to `irohanportfolio.netlify.app`, explaining ML lookup speed. 58 | - **Challenge**: Create a hash index for ML key queries in a portfolio dataset. 59 | 60 | Zip like a boss, and let’s make your SQL skills soar! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/10 Indexing/04 Specialty Indexes/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Specialty Indexes - Unlock ML Query Magic! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Specialty Indexes** like full-text, spatial, or covering indexes tackle unique ML needs, like searching model names or optimizing complex queries. They’re your secret weapon for advanced performance. This guide will teach you specialty indexes with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Variety**: Learn how specialty indexes solve specific problems. 12 | 2. **Study Syntax**: See examples for full-text and covering indexes. 13 | 3. **Run Examples**: Try the indexes below in a database like MySQL or PostgreSQL. 14 | 4. **Test Use Cases**: Query with specialty indexes and verify speed. 15 | 5. **ML Spin**: Use specialty indexes for ML search or optimization. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- Full-Text Index (MySQL) 23 | CREATE FULLTEXT INDEX index_name ON table_name (column_name); 24 | -- Covering Index 25 | CREATE INDEX index_name ON table_name (column1, column2); 26 | ``` 27 | 28 | - **Example 1: Full-Text on Model Name**: 29 | ```sql 30 | CREATE FULLTEXT INDEX idx_model_name_fulltext ON predictions (model_name); 31 | ``` 32 | *Enables ML model name searches with `MATCH`.* 33 | ```sql 34 | SELECT * FROM predictions 35 | WHERE MATCH(model_name) AGAINST('bert' IN BOOLEAN MODE); 36 | ``` 37 | 38 | - **Example 2: Covering Index**: 39 | ```sql 40 | CREATE INDEX idx_model_score ON predictions (model_id, score, prediction_date); 41 | ``` 42 | *Speeds up ML queries by covering multiple columns.* 43 | 44 | - **Example 3: GIN Index (PostgreSQL)**: 45 | ```sql 46 | CREATE INDEX idx_model_gin ON predictions USING GIN (model_name); 47 | ``` 48 | *Optimizes ML text searches in PostgreSQL.* 49 | 50 | --- 51 | 52 | ## 💡 Practice Tips 53 | 54 | - **Tool Time**: Use MySQL Workbench or [pgAdmin](https://www.pgadmin.org) for specialty indexes. 55 | - **ML Use Case**: Specialty indexes enhance ML tasks, like searching model metadata or covering query needs. 56 | - **Try This**: Create `idx_model_name_fulltext`, run a `MATCH` query, and use `EXPLAIN` to confirm index usage. 57 | - **Note**: Full-text needs MySQL’s InnoDB; GIN is PostgreSQL-specific. 58 | 59 | --- 60 | 61 | ## 🚀 Next Steps 62 | 63 | - **Level Up**: Revisit `B-Tree Indexes` for standard use or `Creating Indexes` for basics. 64 | - **Portfolio Win**: Add a specialty index to `irohanportfolio.netlify.app`, showing ML query tricks. 65 | - **Challenge**: Create a full-text index for ML model searches in a portfolio dataset. 66 | 67 | Unlock like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/03 User-Defined Functions/Projects/README.md: -------------------------------------------------------------------------------- 1 | # 🛠️ User-Defined Functions Projects - Custom ML Logic 2 | 3 | ## 🌟 Overview 4 | 5 | **User-Defined Functions (UDFs)** are your secret weapon for custom SQL logic, from metrics to feature preprocessing. These projects will have you crafting scalar and table-valued UDFs for ML tasks, producing portfolio-worthy tools that show off your AI/ML chops. Let’s build some reusable logic for your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 📈 Projects 10 | 11 | ### Project 1: RMSE Metric Function 12 | - **Description**: Create a scalar UDF to compute RMSE for model evaluation, perfect for ML performance tracking. 13 | - **Tasks**: 14 | 1. Use the `predictions` table (`prediction_id INT, model_id INT, score FLOAT, prediction_date DATE`). 15 | 2. Write a PostgreSQL UDF to calculate RMSE between `score` and a predicted value. 16 | 3. Test the UDF on sample data (e.g., `score` vs. 0.9). 17 | 4. Create a query to apply the UDF across all predictions. 18 | 5. Add to your portfolio with a README detailing the UDF and its ML use case. 19 | - **Expected Outcome**: A reusable RMSE function with sample outputs, ready for your portfolio. 20 | - **Challenge Level**: Beginner 21 | 22 | ### Project 2: Feature Normalization Pipeline 23 | - **Description**: Build a UDF-based pipeline to normalize features and return a processed dataset, streamlining ML preprocessing. 24 | - **Tasks**: 25 | 1. Use the `features` table (`feature_id INT, user_id INT, model_id INT, feature FLOAT, category VARCHAR`). 26 | 2. Create a scalar UDF to normalize `feature` values to 0-1 using min-max scaling. 27 | 3. Write a table-valued UDF to return normalized features for a `model_id`. 28 | 4. Combine both UDFs in a query to process features. 29 | 5. Document in your portfolio with code, outputs, and ML pipeline context. 30 | - **Expected Outcome**: A normalization pipeline with UDFs, showcasing preprocessing skills in your portfolio. 31 | - **Challenge Level**: Intermediate 32 | 33 | --- 34 | 35 | ## 🚀 How to Use These Projects 36 | 37 | 1. **Select a Project**: Go Beginner for quick results or Intermediate for a deeper dive. 38 | 2. **Set Up**: Use a DB (PostgreSQL, SQL Server) with the sample tables. 39 | 3. **Code & Test**: Write UDFs, test edge cases (e.g., `NULL`, zeros), and verify outputs. 40 | 4. **Showcase**: Save code and results, then add a README to `irohanportfolio.netlify.app` with ML insights. 41 | 5. **Enhance**: Add new metrics or UDFs to personalize your projects! 42 | 43 | > **Pro Tip**: Integrate UDFs with Python (e.g., via `psycopg2`) for a portfolio that screams ML expertise! 44 | 45 | --- 46 | 47 | ## 📝 Note 48 | 49 | These projects are your stage—shine on it! Customize them (e.g., new metrics, complex UDFs) and push to your portfolio for recruiter cred. Got a UDF project spark? Share it to make this repo epic! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/04 Window Functions/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Window Functions - Rank Your ML Data Like a Star! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Window Functions** perform calculations across rows without grouping, perfect for ranking ML predictions or computing running totals. They’re your key to advanced analytics. This guide will teach you window functions with ML examples, supercharging your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Windows**: Learn how window functions operate over partitions. 12 | 2. **Study Syntax**: See `OVER`, `PARTITION BY`, and `ORDER BY`. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Test Rankings**: Verify function outputs (e.g., ranks, totals). 15 | 5. **ML Spin**: Use window functions for ML model comparisons. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | SELECT column, 23 | function() OVER (PARTITION BY column ORDER BY column) AS alias 24 | FROM table_name; 25 | ``` 26 | 27 | - **Example 1: Rank Predictions**: 28 | ```sql 29 | SELECT model_id, score, 30 | RANK() OVER (PARTITION BY model_id ORDER BY score DESC) AS score_rank 31 | FROM predictions; 32 | ``` 33 | *Ranks ML predictions by score per model.* 34 | 35 | - **Example 2: Running Accuracy Total**: 36 | ```sql 37 | SELECT model_id, accuracy, 38 | SUM(accuracy) OVER (PARTITION BY model_id ORDER BY eval_date) AS running_total 39 | FROM model_metrics; 40 | ``` 41 | *Calculates cumulative ML model accuracy.* 42 | 43 | - **Example 3: Top Score Flag**: 44 | ```sql 45 | SELECT prediction_id, score, 46 | CASE WHEN ROW_NUMBER() OVER (PARTITION BY model_id ORDER BY score DESC) = 1 THEN 'Top' 47 | ELSE 'Other' END AS top_score 48 | FROM predictions; 49 | ``` 50 | *Flags top ML prediction scores per model.* 51 | 52 | --- 53 | 54 | ## 💡 Practice Tips 55 | 56 | - **Tool Time**: Use [SQLFiddle](http://sqlfiddle.com) or PostgreSQL for window functions. 57 | - **ML Use Case**: Window functions rank ML models or track performance trends. 58 | - **Try This**: Run the rank example, check top ranks, and compare with `ORDER BY`. 59 | - **Note**: Use `DENSE_RANK()` for no gaps in rankings—test both to see the difference. 60 | 61 | --- 62 | 63 | ## 🚀 Next Steps 64 | 65 | - **Level Up**: Try `Common Table Expressions` for query clarity or `Pivot Queries` for reshaping. 66 | - **Portfolio Win**: Add a window function to `irohanportfolio.netlify.app`, showing ML rankings. 67 | - **Challenge**: Rank ML predictions by score in a portfolio dataset. 68 | 69 | Rank like a pro, and let’s rock your SQL game! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/04 Window Functions/Projects/README.md: -------------------------------------------------------------------------------- 1 | # 🛠️ Window Functions Projects - ML Analytics Powerhouse 2 | 3 | ## 🌟 Overview 4 | 5 | **Window Functions** unlock powerful analytics for ML, from ranking models to tracking trends, without losing data. These projects will have you building leaderboards and time-series reports using `RANK`, `LAG`, and more, creating portfolio pieces that scream data mastery. Get ready to level up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 📈 Projects 10 | 11 | ### Project 1: Model Leaderboard Generator 12 | - **Description**: Build a leaderboard ranking predictions by score per model, perfect for ML evaluation. 13 | - **Tasks**: 14 | 1. Use the `predictions` table (`prediction_id INT, model_id INT, score FLOAT, prediction_date DATE`). 15 | 2. Write a query using `RANK()` to rank predictions within each `model_id` by `score`. 16 | 3. Test with `DENSE_RANK()` and compare outputs. 17 | 4. Export the leaderboard to a CSV for visualization. 18 | 5. Add to your portfolio with a README explaining the query and ML context. 19 | - **Expected Outcome**: A ranked leaderboard table, ready for your portfolio. 20 | - **Challenge Level**: Beginner 21 | 22 | ### Project 2: Time-Series Trend Analyzer 23 | - **Description**: Create a report tracking score trends over time for models, showcasing ML performance analysis. 24 | - **Tasks**: 25 | 1. Use the `predictions` table. 26 | 2. Write a query with `LAG()` to compute score deltas and `AVG()` for running averages per `model_id`, ordered by `prediction_date`. 27 | 3. Use `ROWS BETWEEN` for a cumulative window. 28 | 4. Save results to a temporary table for dashboard integration. 29 | 5. Document in your portfolio with code, sample trends, and ML use case. 30 | - **Expected Outcome**: A trend report with deltas and averages, boosting your portfolio’s analytics cred. 31 | - **Challenge Level**: Intermediate 32 | 33 | --- 34 | 35 | ## 🚀 How to Use These Projects 36 | 37 | 1. **Pick a Project**: Start with Beginner for quick wins or dive into Intermediate for analytics flair. 38 | 2. **Set Up**: Use a DB (PostgreSQL, MySQL 8.0+, SQL Server) with the sample tables. 39 | 3. **Code & Test**: Write queries, optimize with `EXPLAIN`, and verify rankings or trends. 40 | 4. **Showcase**: Export results (e.g., CSV, screenshot) and add a README to `irohanportfolio.netlify.app` with ML insights. 41 | 5. **Customize**: Add partitions or functions to make projects your own! 42 | 43 | > **Pro Tip**: Visualize trends with Python’s matplotlib for a portfolio that wows ML recruiters! 44 | 45 | --- 46 | 47 | ## 📝 Note 48 | 49 | These projects are your spotlight! Tweak them (e.g., new rankings, time windows) and add to your portfolio to shine. Got a window function project idea? Share it to make this repo epic! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/05 Common Table Expressions/Projects/README.md: -------------------------------------------------------------------------------- 1 | # 🛠️ Common Table Expressions Projects - Structured ML Queries 2 | 3 | ## 🌟 Overview 4 | 5 | **Common Table Expressions (CTEs)** simplify complex ML queries, from multi-step pipelines to recursive hierarchies. These projects will have you building feature processors and graph analyzers, creating portfolio-worthy outputs that show off your SQL structuring skills. Let’s make your *ML-Interview-Preparation-Hub* a recruiter magnet! 🚀 6 | 7 | --- 8 | 9 | ## 📈 Projects 10 | 11 | ### Project 1: High-Score Model Filter 12 | - **Description**: Use CTEs to filter and summarize high-performing models, streamlining ML evaluation. 13 | - **Tasks**: 14 | 1. Use the `predictions` and `models` tables (`model_id INT, model_name VARCHAR, created_date DATE`). 15 | 2. Write a CTE to compute average `score` per `model_id`. 16 | 3. Add a second CTE to join with `models` and filter averages above 0.85. 17 | 4. Export results to a CSV for reporting. 18 | 5. Add to your portfolio with a README detailing the CTEs and ML use case. 19 | - **Expected Outcome**: A filtered model report, ready for your portfolio. 20 | - **Challenge Level**: Beginner 21 | 22 | ### Project 2: Recursive Feature Graph Explorer 23 | - **Description**: Build a recursive CTE to traverse a feature hierarchy, ideal for ML graph analysis. 24 | - **Tasks**: 25 | 1. Use the `features` table with hierarchy (`feature_id INT, parent_id INT, name VARCHAR`). 26 | 2. Write a recursive CTE to list all features, starting from `parent_id IS NULL`. 27 | 3. Include a `level` column to track depth. 28 | 4. Save the hierarchy to a temporary table for visualization. 29 | 5. Document in your portfolio with code, sample graph, and ML context. 30 | - **Expected Outcome**: A feature hierarchy dataset, showcasing graph skills in your portfolio. 31 | - **Challenge Level**: Intermediate 32 | 33 | --- 34 | 35 | ## 🚀 How to Use These Projects 36 | 37 | 1. **Choose a Project**: Start with Beginner for quick setup or tackle Intermediate for recursion flair. 38 | 2. **Set Up**: Use a DB (PostgreSQL, SQL Server) with the sample tables. 39 | 3. **Code & Test**: Build CTEs, test recursion limits, and verify outputs. 40 | 4. **Showcase**: Save results and add a README to `irohanportfolio.netlify.app` with ML insights. 41 | 5. **Enhance**: Add joins or filters to personalize your projects! 42 | 43 | > **Pro Tip**: Pair with a Python graph library (e.g., networkx) for a portfolio that screams ML innovation! 44 | 45 | --- 46 | 47 | ## 📝 Note 48 | 49 | These projects are your canvas! Customize them (e.g., new hierarchies, extra CTEs) and push to your portfolio for recruiter wow-factor. Got a CTE project spark? Share it to make this repo epic! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/06 Specialized Queries/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master Specialized Queries - Unlock ML Data Magic! 2 | 3 | ## 🌟 Welcome 4 | 5 | **Specialized Queries** include JSON, geospatial, or regex queries, tailored for ML tasks like extracting model metadata or filtering predictions. They’re your secret weapon for niche needs. This guide will teach you specialized queries with ML examples, wrapping up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Variety**: Learn how specialized queries handle unique data. 12 | 2. **Study Syntax**: Explore JSON or regex examples. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Test Use Cases**: Verify outputs for specific ML needs. 15 | 5. **ML Spin**: Apply specialized queries to ML data extraction. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- JSON Query (PostgreSQL) 23 | SELECT column->'key' FROM table_name; 24 | -- Regex Query 25 | SELECT column FROM table_name WHERE column REGEXP 'pattern'; 26 | ``` 27 | 28 | - **Example 1: JSON Query (Hypothetical JSON Column)**: 29 | ```sql 30 | -- Assume predictions has json_data: {"model_version": "v1"} 31 | SELECT model_id, json_data->>'model_version' AS version 32 | FROM predictions; 33 | ``` 34 | *Extracts ML model versions from JSON.* 35 | 36 | - **Example 2: Regex Filter**: 37 | ```sql 38 | SELECT model_id, model_name 39 | FROM predictions 40 | WHERE model_name REGEXP '^BERT'; 41 | ``` 42 | *Finds ML models starting with ‘BERT’.* 43 | 44 | - **Example 3: Geospatial Query (Hypothetical Coordinates)**: 45 | ```sql 46 | -- Assume predictions has location: POINT(latitude, longitude) 47 | SELECT model_id, 48 | ST_Distance(location, ST_SetSRID(ST_MakePoint(0, 0), 4326)) AS distance 49 | FROM predictions 50 | WHERE ST_DWithin(location, ST_SetSRID(ST_MakePoint(0, 0), 4326), 1000); 51 | ``` 52 | *Filters ML predictions by location (PostgreSQL PostGIS).* 53 | 54 | --- 55 | 56 | ## 💡 Practice Tips 57 | 58 | - **Tool Time**: Use [DBeaver](https://dbeaver.io) or PostgreSQL for specialized queries. 59 | - **ML Use Case**: Specialized queries extract ML metadata, like JSON configs or model patterns. 60 | - **Try This**: Run the regex query, tweak the pattern, and verify matching rows. 61 | - **Note**: JSON/geospatial needs extensions (e.g., PostGIS)—check DB support first. 62 | 63 | --- 64 | 65 | ## 🚀 Next Steps 66 | 67 | - **Level Up**: Revisit `User-Defined Functions` for custom logic or `CTEs` for clarity. 68 | - **Portfolio Win**: Add a specialized query to `irohanportfolio.netlify.app`, showing ML data tricks. 69 | - **Challenge**: Write a JSON query for ML metadata in a portfolio dataset. 70 | 71 | Unlock like a pro, and let’s finish your SQL journey with a bang! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/06 Specialized Queries/Projects/README.md: -------------------------------------------------------------------------------- 1 | # 🛠️ Specialized Queries Projects - Advanced ML Data Tools 2 | 3 | ## 🌟 Overview 4 | 5 | **Specialized Queries** unlock advanced SQL for ML, from parsing JSON configs to syncing data with `MERGE`. These projects will have you building config parsers and optimized pipelines, creating portfolio pieces that show off your versatility. Get ready to make your *ML-Interview-Preparation-Hub* shine for AI/ML roles! 🚀 6 | 7 | --- 8 | 9 | ## 📈 Projects 10 | 11 | ### Project 1: JSON Config Parser 12 | - **Description**: Build a query to extract hyperparameters from JSON configs, streamlining ML model analysis. 13 | - **Tasks**: 14 | 1. Use the `model_configs` table (`model_id INT, config JSON`). 15 | 2. Write a PostgreSQL query to extract `learning_rate` and `model_type` from `config`. 16 | 3. Test with sample JSON data (e.g., `{"hyperparams": {"lr": 0.01}, "model_type": "neural_net"}`). 17 | 4. Export results to a CSV for reporting. 18 | 5. Add to your portfolio with a README explaining the query and ML context. 19 | - **Expected Outcome**: A parsed config dataset, ready for your portfolio. 20 | - **Challenge Level**: Beginner 21 | 22 | ### Project 2: Data Sync and Partition Optimizer 23 | - **Description**: Create a `MERGE`-based pipeline with partitioned tables for efficient ML data updates. 24 | - **Tasks**: 25 | 1. Use the `predictions` and `new_predictions` tables (`prediction_id INT, score FLOAT`). 26 | 2. Write a `MERGE` query (SQL Server) to update or insert predictions. 27 | 3. Partition the `predictions` table by `prediction_date` (e.g., 2025 range). 28 | 4. Add a query hint to optimize reads from the partitioned table. 29 | 5. Document in your portfolio with code, partition schema, and ML pipeline context. 30 | - **Expected Outcome**: A synced, partitioned dataset with optimized queries, boosting your portfolio’s scalability cred. 31 | - **Challenge Level**: Intermediate 32 | 33 | --- 34 | 35 | ## 🚀 How to Use These Projects 36 | 37 | 1. **Pick a Project**: Go Beginner for quick parsing or Intermediate for pipeline depth. 38 | 2. **Set Up**: Use a DB (PostgreSQL, SQL Server) with the sample tables. 39 | 3. **Code & Test**: Write queries, validate with `EXPLAIN`, and ensure JSON or partition correctness. 40 | 4. **Showcase**: Save results and add a README to `irohanportfolio.netlify.app` with ML insights. 41 | 5. **Customize**: Add JSON fields or partition keys to make projects your own! 42 | 43 | > **Pro Tip**: Integrate with Python’s `pandas` or `sqlalchemy` for a portfolio that wows ML recruiters! 44 | 45 | --- 46 | 47 | ## 📝 Note 48 | 49 | These projects are your spotlight! Tweak them (e.g., new JSON fields, partition strategies) and add to your portfolio to stand out. Got a specialized query project idea? Share it to make this repo epic! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/07 DateTime Functions/Learning/README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Master DateTime Functions - Unlock Time-Series ML Magic! 2 | 3 | ## 🌟 Welcome 4 | 5 | **DateTime Functions** in SQL are your key to mastering time-based data, perfect for ML tasks like tracking prediction trends or scheduling model runs. From extracting months to aggregating by weeks, these functions handle time-series with ease. This guide will teach you datetime queries with ML examples, leveling up your *ML-Interview-Preparation-Hub*! 🚀 6 | 7 | --- 8 | 9 | ## 🛤️ Learning Path 10 | 11 | 1. **Understand Time**: Learn how datetime functions manipulate dates and times. 12 | 2. **Study Syntax**: Explore `EXTRACT`, `DATE_TRUNC`, and `INTERVAL` examples. 13 | 3. **Run Examples**: Try the queries below in a database like PostgreSQL. 14 | 4. **Test Use Cases**: Verify outputs for specific ML needs, like trend analysis. 15 | 5. **ML Spin**: Apply datetime queries to ML data, like prediction timelines. 16 | 17 | --- 18 | 19 | ## 📜 Syntax 20 | 21 | ```sql 22 | -- Date Extraction 23 | SELECT EXTRACT(part FROM date_column) FROM table_name; 24 | -- Time Aggregation 25 | SELECT DATE_TRUNC('unit', date_column) FROM table_name GROUP BY 1; 26 | ``` 27 | 28 | - **Example 1: Extract Prediction Month**: 29 | ```sql 30 | SELECT prediction_id, EXTRACT(MONTH FROM prediction_date) AS prediction_month 31 | FROM predictions; 32 | ``` 33 | *Extracts the month from ML predictions for filtering or analysis.* 34 | 35 | - **Example 2: Weekly Score Trends**: 36 | ```sql 37 | SELECT DATE_TRUNC('week', prediction_date) AS week, 38 | AVG(score) AS avg_score 39 | FROM predictions 40 | GROUP BY week 41 | ORDER BY week; 42 | ``` 43 | *Aggregates ML prediction scores by week for performance tracking.* 44 | 45 | - **Example 3: Schedule Retraining**: 46 | ```sql 47 | SELECT model_id, 48 | prediction_date + INTERVAL '30 days' AS retrain_date 49 | FROM predictions 50 | WHERE prediction_date >= '2025-04-01'; 51 | ``` 52 | *Sets future retraining dates for ML models.* 53 | 54 | --- 55 | 56 | ## 💡 Practice Tips 57 | 58 | - **Tool Time**: Use [DBeaver](https://dbeaver.io) or MySQL/PostgreSQL for datetime queries. 59 | - **ML Use Case**: Datetime functions track ML prediction trends or schedule jobs, like monthly reports. 60 | - **Try This**: Run the weekly trends query, tweak the period (e.g., month), and check results. 61 | - **Note**: MySQL uses `DATE_FORMAT` instead of `DATE_TRUNC`—test both for interviews. 62 | 63 | --- 64 | 65 | ## 🚀 Next Steps 66 | 67 | - **Level Up**: Revisit `Window Functions` for running totals over time or `CTEs` for recursive date ranges. 68 | - **Portfolio Win**: Add a datetime query to `irohanportfolio.netlify.app`, showing ML trend insights. 69 | - **Challenge**: Write a monthly aggregation query for ML predictions in a portfolio dataset. 70 | 71 | Master time like a pro, and let’s finish your SQL journey with a bang! 🌟 -------------------------------------------------------------------------------- /SQL Fundamentals/11 Extra Modules/07 DateTime Functions/Projects/README.md: -------------------------------------------------------------------------------- 1 | # 🛠️ DateTime Functions Projects - Master Time-Series ML Tools 2 | 3 | ## 🌟 Overview 4 | 5 | **DateTime Functions** unlock SQL’s power for time-based ML tasks, from analyzing prediction trends to scheduling model jobs. These projects will have you building trend trackers and performance pipelines, creating portfolio pieces that showcase your time-series skills. Get ready to make your *ML-Interview-Preparation-Hub* shine for AI/ML roles! 🚀 6 | 7 | --- 8 | 9 | ## 📈 Projects 10 | 11 | ### Project 1: Monthly Prediction Summarizer 12 | - **Description**: Build a query to summarize ML prediction scores by month, creating a time-series report for analysis. 13 | - **Tasks**: 14 | 1. Use the `predictions` table (`prediction_id INT, model_id INT, score FLOAT, prediction_date DATE, model_name VARCHAR`). 15 | 2. Write a PostgreSQL query to calculate average `score` per month in 2025. 16 | 3. Test with sample data (e.g., `prediction_date` from Jan to Dec 2025). 17 | 4. Export results to a CSV for ML reporting. 18 | 5. Add to your portfolio with a README explaining the query and ML trend context. 19 | - **Expected Outcome**: A monthly trend dataset, ready for your portfolio. 20 | - **Challenge Level**: Beginner 21 | 22 | ### Project 2: Recent Model Performance Pipeline 23 | - **Description**: Create a time-filtered pipeline joining predictions with model training dates for performance insights. 24 | - **Tasks**: 25 | 1. Use the `predictions` and `models` tables (`model_id INT, trained_date DATE`). 26 | 2. Write a query to find average `score` for predictions within 30 days of `trained_date` in 2025. 27 | 3. Add an index on `prediction_date` to optimize filtering. 28 | 4. Save results as a CSV for ML evaluation. 29 | 5. Document in your portfolio with code, index details, and ML pipeline context. 30 | - **Expected Outcome**: A performance report with optimized queries, boosting your portfolio’s scalability cred. 31 | - **Challenge Level**: Intermediate 32 | 33 | --- 34 | 35 | ## 🚀 How to Use These Projects 36 | 37 | 1. **Pick a Project**: Go Beginner for quick trends or Intermediate for pipeline depth. 38 | 2. **Set Up**: Use a DB (PostgreSQL, MySQL) with the sample tables. 39 | 3. **Code & Test**: Write queries, validate with `EXPLAIN`, and ensure date logic correctness. 40 | 4. **Showcase**: Save results and add a README to `irohanportfolio.netlify.app` with ML insights. 41 | 5. **Customize**: Add time periods or filters to make projects your own! 42 | 43 | > **Pro Tip**: Integrate with Python’s `pandas` or `sqlalchemy` for a portfolio that wows ML recruiters! 44 | 45 | --- 46 | 47 | ## 📝 Note 48 | 49 | These projects are your spotlight! Tweak them (e.g., new time periods, aggregations) and add to your portfolio to stand out. Got a datetime project idea? Share it to make this repo epic! 🌟 --------------------------------------------------------------------------------