SQL JOIN Example

This SQL example creates two small tables and joins them. It is useful for practicing relational thinking without connecting to a production database.

SQL Compiler

Code Example

CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE courses (student_id INTEGER, course TEXT);

INSERT INTO students VALUES (1, 'Mayur'), (2, 'Priya');
INSERT INTO courses VALUES (1, 'Python'), (1, 'SQL'), (2, 'JavaScript');

SELECT students.name, courses.course
FROM students
JOIN courses ON students.id = courses.student_id
ORDER BY students.name;

Expected Output

Mayur | Python
Mayur | SQL
Priya | JavaScript

Practice Steps

  1. Open the SQL editor and paste the query.
  2. Run it to create tables, insert rows, and print joined results.
  3. Add another student or filter by course name.
HOME LEARN COMMUNITY DASHBOARD