#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
Learning SQL LEFT JOIN in 60 Days
More Relevant Posts
-
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
-
#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
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
-
-
Today I started learning SQL and practiced some real queries 💻 I created an employees table, inserted data, and worked on different operations like: •retrieving data •updating records •deleting entries •altering table structure •sorting and filtering data I also explored how small changes in queries can impact the output, which helped me understand SQL much better. To make my learning more practical, I solved multiple questions and recorded a video where I explained: • how each query works • how results change step by step • how we can visualize and understand data easily Some key things I learned today: •Writing clean and correct SQL queries • Using conditions like CHECK, ORDER BY, and WHERE • Updating and modifying tables without errors • Thinking logically while solving database problems This is just the beginning, but I’m really enjoying the process of learning and improving step by step 🚀 #SQL #LearningJourney #DataBasics #PlacementPreparation #StudentLife
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_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
-
-
From simple queries to real-world SQL thinking 🚀 ---------------------------------------------------------------- Today I solved a problem where I had to analyze transactions data and report: • Total transactions • Approved transactions • Total amount • Approved amount • Grouped by month and country At first, it looked like a basic aggregation problem… but it actually required combining multiple concepts: ✔ Extracting month from date ✔ Grouping on multiple columns ✔ Conditional aggregation ✔ Writing clean and scalable SQL 🧠 Key learning: Instead of writing multiple queries, everything can be solved in a single query using conditional aggregation. 💡 One powerful trick: Using conditions inside SUM: SUM(state = 'approved') This helped me count approved transactions efficiently. 💻 Solution: SELECT DATE_FORMAT(trans_date, '%Y-%m') AS month, country, COUNT(*) AS trans_count, SUM(state = 'approved') AS approved_count, SUM(amount) AS trans_total_amount, SUM(CASE WHEN state = 'approved' THEN amount ELSE 0 END) AS approved_total_amount FROM Transactions GROUP BY DATE_FORMAT(trans_date, '%Y-%m'), country; 🚀 This problem helped me strengthen: SQL aggregation • Data analysis thinking • Real-world query logic Learning SQL step by step and sharing the journey 👇 #SQL #DataAnalytics #LearningInPublic #LeetCode #100DaysOfCode
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
-
-
📊 Day 62/90 — SQL Learning: Subqueries in WHERE & SELECT Today I went deeper into subqueries: 👉 Using subqueries in WHERE & SELECT This made SQL feel even more powerful 🔥 Here’s what I learned: ✅ Subquery in "WHERE" → filter data dynamically ✅ Subquery in "SELECT" → create calculated columns ✅ Helps avoid multiple queries ✅ Makes analysis more efficient --- 🔹 Example 1 (WHERE): 👉 Find employees earning more than average SELECT name, salary FROM employees WHERE salary > ( SELECT AVG(salary) FROM employees ); --- 🔹 Example 2 (SELECT): 👉 Show salary + average salary SELECT name, salary, (SELECT AVG(salary) FROM employees) AS avg_salary FROM employees; --- 💡 Big lesson: Subqueries make your queries dynamic and intelligent Because: Static query → Limited ❌ Dynamic query → Smart analysis ✅ From today, I’m writing more efficient and flexible SQL queries 🚀 💬 Which one do you use more: WHERE or SELECT subqueries? #SQL #DataAnalytics #LearningInPublic #DataAnalystJourney #90DaysChallenge
To view or add a comment, sign in
-
-
Most people learning SQL confuse window functions with aggregate functions, but they serve very different purposes. Aggregate Functions- Aggregate functions return a single result for a group of rows. Examples include COUNT() SUM() AVG() MAX() MIN() Once you use them, your rows are grouped and you lose row-level detail. Window Functions- Window functions, on the other hand, perform calculations across a set of rows without collapsing them. They allow you to retain the original rows while adding computed values. Examples include ROW_NUMBER() RANK() DENSE_RANK() SUM() OVER() AVG() OVER() Think of it this way Aggregate functions summarize data, while window functions enrich data. Other Types of SQL Functions You Should Know Scalar Functions → Work on a single value (e.g., UPPER(), LOWER(), LEN()) String Functions → Manipulate text (e.g., CONCAT(), SUBSTRING()) Date Functions → Handle date and time (e.g., GETDATE(), DATEADD()) Analytical Functions → Advanced calculations (e.g., LAG(), LEAD()) Understanding when to use each type is what separates a beginner from a solid SQL professional. Which one do you use more often, window functions or aggregate functions? #SQL #DataAnalytics #TechGrowth #Learning #Database #Developers
To view or add a comment, sign in
-
Explore related topics
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