HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges
  • Testimonials

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Builders
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer
  • Games

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap

Build 2.139 · 05 Nov 2026, 10:27 UTC

    HackIndia
    HackathonsNewsInternshipsSkillsGrowthPro Perks
    Working towardsSQL
    0%

    0 of 10 steps done · +100 XP · +50 SHARP when it is yours

    1. 1Model one real feature4 min · +10 XP · +5 SHARP
    2. 2Use primary and foreign keys4 min · +10 XP · +5 SHARP
    3. 3Read data with SELECT4 min · +10 XP · +5 SHARP
    4. 4Combine data with JOINs4 min · +10 XP · +5 SHARP
    5. 5Summarise with GROUP BY4 min · +10 XP · +5 SHARP
    6. 6Find slow queries5 min · +10 XP · +5 SHARP
    7. 7Stop SQL injection4 min · +10 XP · +5 SHARP
    8. 8Ship the SQL feature repo5 min · +10 XP · +5 SHARP
    9. The check10 questions, 7 to pass · +10 SHARP
    10. Hand in the taskA project that uses the skill
    11. Skill and certificate+100 XP · +50 SHARP
    Lesson 4 of 8 4 min

    SQL

    Combine data with JOINs

    • +10 XP for this lesson
    • +100 XP when the skill is proved
    • Nobody here has proved it yet
    In 30 seconds
    • Use JOIN to read related rows from two tables in one result.
    • Choose INNER or LEFT JOIN based on missing matches.
    Add one joined query to your SQL feature repo with a clear sample.
    Key point

    One idea

    A JOIN connects rows using a relationship, usually a foreign key pointing to a primary key. You use it when the data you need is split across tables.

    Why JOINs matter

    Your feature should not store the same detail in many places. For example, an orders table can store user_id, while the users table stores the user name and phone.

    When you need to show an order list with buyer names, you combine orders and users in the query. You do not copy the user name into every order row.

    Example

    Basic INNER JOIN

    Use INNER JOIN when you only want rows that have a match in both tables. This is good for required relationships, like an order that must belong to a user.

    -- List orders with buyer details
    SELECT
      orders.id AS order_id,
      orders.total_rupees,
      orders.status,
      users.name AS buyer_name,
      users.email AS buyer_email
    FROM orders
    INNER JOIN users
      ON orders.user_id = users.id
    ORDER BY orders.id DESC;

    Read the query

    FROM says the main table you are reading from. INNER JOIN names the second table. ON explains how the two tables match.

    Use table names before column names when both tables may have the same column, like id or created_at. Use AS to give readable names to the output.

    Example

    LEFT JOIN for missing data

    Use LEFT JOIN when you want every row from the left table, even if the joined table has no match. This helps with optional data.

    For example, not every student profile may have a submitted project yet. A LEFT JOIN can still show all students.

    -- Show all students, with project title if submitted
    SELECT
      students.id AS student_id,
      students.name,
      projects.title AS project_title
    FROM students
    LEFT JOIN projects
      ON projects.student_id = students.id
    ORDER BY students.name;
    Common mistake

    Common mistake

    Do not join tables without an ON condition. You can accidentally create too many rows, where every row from one table is paired with every row from the other.

    If your result suddenly has hundreds of rows for a small seed file, check your ON line first.

    Tip

    Use AI safely

    You can ask ChatGPT or Gemini to draft a JOIN query from your schema. Paste only your table definitions, not private data.

    Then check three things yourself: the ON condition uses the right keys, the JOIN type matches your need, and the selected columns have clear aliases.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Quick check

    0 of 2 right
    1.Your orders table has user_id. You need order totals with buyer names. What should you use?
    2.You need to list all students, even those without a submitted project. Which JOIN fits best?

    Answer the quick check to finish this lesson.

    ← Lesson 3Skip to lesson 5 →
    Working towards
    SQL +100 XP

    0 of 8 lessons done · proved by a project that uses the skill

    See the track