MySQL is a relational database management system (RDBMS). This means it stores data in a structured format using **tables** and allows relationships between those tables using keys.
Let's imagine a school database with two related tables:
student_id | name | class |
---|---|---|
1 | Amit | 10 |
mark_id | student_id | subject | score |
---|---|---|---|
101 | 1 | Math | 88 |
The student_id in the Marks table is a foreign key that links back to the Students table. This is how relationships are created.
-- Create Students table CREATE TABLE students ( student_id INT PRIMARY KEY, name VARCHAR(50), class INT ); -- Create Marks table with foreign key CREATE TABLE marks ( mark_id INT PRIMARY KEY, student_id INT, subject VARCHAR(50), score INT, FOREIGN KEY (student_id) REFERENCES students(student_id) );
-- Join both tables to see student names with marks SELECT students.name, marks.subject, marks.score FROM students JOIN marks ON students.student_id = marks.student_id;
JOIN
to combine data from multiple tables.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!