#Day_34 of learning SQL in 60 days Topic I covered: A SELF JOIN is when a table is joined with itself. It might sound confusing at first, but it’s extremely useful when working with hierarchical data. When do we use SELF JOIN? When a table contains related data within itself. Example: Employees and their Managers are stored in the same table. How it works: We use table aliases to treat the same table as two different tables. Syntax: SELECT A.COLUMN_NAME, B.COLUMN_NAME FROM TABLE_NAME A JOIN TABLE_NAME B ON A.COMMON_COLUMN = B.COMMON_COLUMN; Example: select e.emp_name as employe,m.emp_name as manager from employees e join employees m on e.manager_id=m.emp_id; Here: E represents Employees M represents Managers (same table!) Key Takeaways: ✔ SELF JOIN joins a table to itself ✔ Requires aliases to differentiate roles ✔ Useful for hierarchical relationships This concept really helped me understand how relational databases handle real-world relationships within the same dataset. #SQL #MySQL #Database #LearningJourney #TechSkills
SELF JOIN in SQL: Joining a Table with Itself
More Relevant Posts
-
#Day_31 of learning SQL in 60 days Topic I covered: SQL Concept I Learned: LEFT JOIN Today I explored LEFT JOIN in SQL, and it really helped me understand how to work with incomplete or missing data. A LEFT JOIN in SQL is used to retrieve all records from the left table and the matching records from the right table. If there is no match, the result will still include the left table’s row, but the right table’s columns will contain NULL values. Syntax: SELECT COLUMN_NAME(S) FROM TABLE1 LEFT JOIN TABLE2 ON TABLE1.COMMON_COLUMN=TABLE2.COMMON_COLUMN; A LEFT JOIN returns: ✔️ All records from the left table ✔️ Matching records from the right table ✔️ NULL values if there is no match Example: SELECT STAFF.EMP_NAME, DEPARTMENTS.DEPT_NAME FROM STAFF LEFT JOIN DEPARTMENTS ON STAFF.DEPT_ID=DEPARTMENTS.DEPT_ID; This query shows all EMPLOYEE NAMES along with their department names. If the EMPLOYEE is not assigned to any department, the department column will show NULL. Use Cases: 🔹 Finding missing or unmatched data 🔹 Displaying complete lists with optional details 🔹 Data analysis where not all records have relationships Learning SQL step by step and building a strong foundation in joins! #SQL #Database #Learning #Tech #DataAnalytics
To view or add a comment, sign in
-
-
The final video in my intermediate SQL series on YouTube is now up! If your SQL queries are starting to get longer, messier, and harder to explain, this is one of the most important skills you can learn next: CTEs, or Common Table Expressions. A lot of people can write SQL that works. Fewer people can write SQL that is clean, structured, easy to read, and easy to talk through in an interview or on the job. That is where CTEs really start to matter. In this video, I break down: • what CTEs are • why they are so useful • how they compare to subqueries • how to use them for cleaner, more professional SQL • how they can help with more layered analysis using healthcare data examples I also walk through exactly how to write them in MySQL and explain why CTEs are especially valuable when you are working with more complex logic, summaries, and multiple steps in one query. If you're trying to get stronger at SQL for data analytics, healthcare analytics, health informatics, or just want to write better SQL overall, this video will help you level up. My goal with this series has always been simple: help people build real SQL confidence so they can stop second guessing themselves and start feeling ready for interviews, projects, and real world work. ♻️ Repost if you know someone learning SQL 🟦 Follow Informessor for more content on health informatics, healthcare analytics, health tech, and AI in healthcare -------------------------------- Get access to my FREE SQL Kit: https://lnkd.in/gcDTU_vW Check out my beginner-level SQL tutorial videos: https://lnkd.in/gYmnjsJu Check out my intermediate-level SQL tutorial videos: https://lnkd.in/g5CV-G98 https://lnkd.in/gXnHgeB3
SQL CTEs Explained Clearly | Healthcare Data Examples | Intermediate SQL Tutorial
https://www.youtube.com/
To view or add a comment, sign in
-
#Day_35 of learning SQL in 60 days Topic I covered: Exploring Multiple Table Joins in SQL As I continue learning SQL, I recently explored an important concept — joining multiple tables to extract meaningful insights from relational data. In real-world databases, data is often distributed across multiple tables. To analyze such data effectively, we use multiple joins. What are Multiple Table Joins? They allow us to combine data from more than two tables using relationships between columns (usually keys). Example Scenario: Suppose we have three tables: departemts staff students Syntax: SELECT COLUMN_NAME(S) FROM TABLE1 JOIN TABLE2 ON TABLE1.COMMON_COLUMN=TABLE2.COMMON_COLUMN JOIN TABLE3 ON TABLE2.COMMON_COLUMN=TABLE3.COMMON_COLUMN; Sample Query: SELECT DEPARTMENTS.DEPT_NAME, STUDENTS.S_NAME, SUBJECTS.SUBJECT_NAME FROM DEPARTMENTS JOIN STUDENTS ON DEPARTMENTS.DEPT_ID=STUDENTS.DEPT JOIN SUBJECTS ON STUDENTS.DEPT=SUBJECTS.DEPT; Key Takeaways: ✔ Helps in combining related data from multiple tables ✔ Improves data analysis and reporting ✔ Commonly used in real-world applications 🚀 Learning SQL step by step and building a strong foundation in data handling! #SQL #Database #LearningJourney #DataAnalytics #MySQL #TechSkills
To view or add a comment, sign in
-
-
Basic SQL Queries Every Beginner Should Know If you’re starting your journey in data analysis, learning SQL is a must. But the good news is you don’t need to know everything at once. Here are some basic SQL queries every beginner should know: 1️⃣ SELECT Used to retrieve data from a table. 👉 Example: "SELECT * FROM customers;" 2️⃣ WHERE Used to filter data based on conditions. 👉 Example: "SELECT * FROM customers WHERE country = 'Nigeria';" 3️⃣ ORDER BY Used to sort data (ascending or descending). 👉 Example: "SELECT * FROM customers ORDER BY age DESC;" 4️⃣ GROUP BY Used to group data and perform aggregations. 👉 Example: "SELECT country, COUNT(*) FROM customers GROUP BY country;" 5️⃣ COUNT / SUM / AVG Aggregate functions used to summarize data. 👉 Example: "SELECT AVG(salary) FROM employees;" 6️⃣ JOIN Used to combine data from multiple tables. 👉 Example: "SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id;" 💡 Why this matters: These queries form the foundation of SQL. Once you understand them, working with databases becomes much easier. You don’t need to master SQL in one day just start with the basics and keep practicing. Which SQL query did you learn first? #DataAnalytics #SQL #DataScience #LearningInPublic #TechSkills #BeginnerFriendly
To view or add a comment, sign in
-
-
🚀My Data Analytics Journey – Getting Started with SQL Today, I began my journey into SQL, one of the most essential skills for any data professional. 💾 Introduction to Databases & SQL A database is an organized collection of data, and a Relational Database stores data in structured tables (rows and columns) with relationships between them. 🧠 What is SQL? SQL (Structured Query Language) is a programming language used to interact with databases. It helps in: • Retrieving data • Inserting new data • Updating existing data • Deleting data It provides a standardized way to communicate with Relational Database Management Systems (RDBMS). ⚙️ Popular SQL Platforms There are several platforms available to work with SQL, including both open-source and enterprise solutions. 📂 Types of SQL Commands 🔹 DDL (Data Definition Language) Used to define and modify database structure: • CREATE, ALTER, DROP, TRUNCATE 🔹 DQL (Data Query Language) Used to retrieve data: • SELECT 🔹 DML (Data Manipulation Language) Used to manage data within tables: • INSERT, UPDATE, DELETE 🔹 DCL (Data Control Language) Used for permissions and access control: • GRANT, REVOKE 🔹 TCL (Transaction Control Language) Used to manage transactions: • COMMIT, ROLLBACK, SAVEPOINT 💡 Key Takeaway: SQL is the backbone of data handling, and mastering it is crucial for efficient data analysis and database management. #SQL #DataAnalytics #LearningJourney #Database #RDBMS #DataScience #CareerGrowth
To view or add a comment, sign in
-
-
🚀 Day 9 of My SQL Learning Journey — Understanding the HAVING Clause 📊 Today I learned a small SQL concept that makes a big difference in real-world data analysis — HAVING. Most people stop at WHERE. But real insights start after grouping data. 🔹 WHERE filters rows 🔹 HAVING filters grouped results 👉 That means HAVING helps answer questions like: ✔ Which departments have more employees? ✔ Which customers appear multiple times? ✔ Which groups cross a certain threshold? 💡 Key Realisation: Data analysis isn’t just about retrieving rows — it’s about filtering meaningful summaries. Learning SQL this way is changing how I think about data, not just how I write queries. 📈 One concept at a time. Done right. On to Day 10… 🚀 #SQL #DataAnalytics #LearningInPublic #MySQL #HAVING #Consistency #CareerGrowth #Placements #CSE
To view or add a comment, sign in
-
My SQL learning Journal Day 32: SQLComments 📝 Today, I explored the SQL comments, and it's the smallest SQL feature with the biggest impact on teamwork. What is a SQL comment? Comments are used to explain SQL code or to temporarily prevent execution of SQL code (for debugging). Comments are ignored by the database engine. It simply means: Text in your code that the database ignores. It is just for you and anyone else reading your query. Two types I learned today: 1. Single-line comment: Single-line comments start with -- and continue to the end of the line. Any text after -- and to the end of the line will be ignored. sql syntax -- This query finds active customers SELECT * FROM customers WHERE status = 'active'; 2. Multi-line comment Multi-line comments start with /* and end with */. Any text between /* and */ will be ignored. sql syntax /* This query calculates monthly sales. Last updated: Day 32. */ SELECT SUM(amount) FROM sales WHERE month = 'APR'; Why this is important: Code runs for machines. Comments explain for humans. Note: Comments are not supported in Microsoft Access databases. #SQL #Data Analytics#Women in Tech #LearningInPublic #BeginnerSQL
To view or add a comment, sign in
-
Two Tables Walk Into SQL. One Saves Data. One Just Pretends To. Temporary Tables vs. Views and why knowing the difference actually matters. My SQL journey keeps adding new layers. This week my tutor introduced two tools I had seen mentioned before but never truly understood: Temporary Tables and Views. They sound similar. They behave very differently. Temporary Table Actually stores data in your computer's memory. Private to your session. Nobody else can see it. Can be inserted, updated and deleted like a real table. Disappears the moment your session ends. Useful for breaking complex queries into steps. View A virtual table. Stores no data of its own. Lives in the database until you explicitly delete it. Essentially a saved query that runs on demand. Uses computing power every time it runs. Cannot always be updated directly. Real World Scenario Imagine you are a data analyst at a bank. You need to calculate each customer's average transaction value, then use that to flag anyone spending more than three times their average in a single day. That is a two-step problem. You would use a temporary table to store the average values first then query from that result to identify the flagged transactions. Clean. Staged. No need to rewrite everything into one overwhelming query. "A View is a window into your data. A Temporary Table is a workbench built for the job, cleared when you are done." Every class is a new concept. Every concept builds on the last. The more SQL I learn, the more I realise this language rewards people who think before they type. Still learning. Still going. Guided by Obumneme Udeinya #DataAnalytics #LearningInPublic #SQL #Cohort6 #Database
To view or add a comment, sign in
-
-
Most people learn SQL. Fewer people learn to think in SQL. There's a difference. Learning SQL means you can write a JOIN or a GROUP BY when you see the problem coming. Thinking in SQL means you look at a messy business question and your brain automatically breaks it into layers like what's the grain of this data, where does it need to be aggregated, what's the most efficient path to get there. That shift didn't happen for me in a classroom. It happened when I was building ETL pipelines and a query that looked perfectly fine was silently returning duplicate rows because I hadn't accounted for a many-to-many join upstream. A few things that actually moved the needle: → Writing CTEs instead of subqueries that forces you to name each logic step, which forces you to understand it. → Thinking about indexes before writing joins on large tables. → Reading query execution plans, not just query results. The last one is underrated. The result can look correct and the query can still be costing you 10x more than it should. SQL is one of those skills where the gap between "I know it" and "I actually know it" is wider than most people admit. What's the SQL concept that took you the longest to really click? #SQL #DataAnalytics #DataEngineering
To view or add a comment, sign in
-
#Day_19 of learning SQL in 60 days Topic I covered: Understanding the HAVING Clause in SQL Recently, I learned about the HAVING clause in SQL, and it’s a great addition when working with grouped data! What is HAVING? The HAVING clause is used to filter grouped data after applying the GROUP BY clause. While WHERE filters rows before grouping, HAVING filters after grouping. Syntax: SELECT column1, aggregate_function(column2) FROM table_name WHERE condition GROUP BY column1 HAVING condition; 🔹 Example: SELECT DEPT_ID, COUNT (*) AS TOTAL FROM STAFF GROUP BY DEPT_ID HAVING COUNT (*)>2; 👉 This query returns only those departments that have more than 2 employees. 🔹 Key Points: ✔ Used with GROUP BY ✔ Works with aggregate functions like COUNT(), SUM(), AVG() ✔ Filters grouped results, not individual rows 💡 Learning how to use HAVING helps in performing advanced data analysis and extracting meaningful insights from datasets. #SQL #Database #LearningSQL #DataAnalytics #TechSkills
To view or add a comment, sign in
-
Explore related topics
- SQL Learning Resources and Tips
- SQL Learning Strategies That Work
- How to Master SQL Techniques
- SQL Learning Roadmap for Beginners
- How to Understand SQL Commands
- SQL Learning and Reference Resources for Data Roles
- Tips for Applying SQL Concepts
- How to Solve Real-World SQL Problems
- Essential SQL Clauses to Understand
- How to Understand SQL Query Execution Order
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development