0% found this document useful (0 votes)
2 views4 pages

Rdbms Lab Exercise

The document outlines a procedure for creating two tables, 'students' and 'courses', in a database named 'college', which share a common column 'student_id'. It details the steps for inserting records into both tables, performing an inner join to retrieve related data, and executing a union to combine results from both tables. The overall aim is to demonstrate table operations using SQL commands effectively.

Uploaded by

Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Rdbms Lab Exercise

The document outlines a procedure for creating two tables, 'students' and 'courses', in a database named 'college', which share a common column 'student_id'. It details the steps for inserting records into both tables, performing an inner join to retrieve related data, and executing a union to combine results from both tables. The overall aim is to demonstrate table operations using SQL commands effectively.

Uploaded by

Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ex.No.

8 TABLE OPERATIONS USING JOIN AND UNION

Statement of problem
create any two tables with common column name and perform join and union

Aim

To create any two tables with common column name and perform join and union

PROCEDURE:
Create Database
 CREATE DATABASE college;
show the database
 SHOW DATABASES;
Using the database
 USE college;

Create the 'students' table

 CREATE TABLE students (


student_id INT PRIMARY KEY,
student_name VARCHAR(50),
age INT
);
 Desc students;
 CREATE TABLE courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(50),
student_id INT,
FOREIGN KEY (student_id) REFERENCES students(student_id)
);
 Desc courses;
Insert some records into the 'students' and ‘ courses’ table
 I INSERT INTO students (student_id, student_name, age) VALUES
(1, 'Alice', 20),
(2, 'Bob', 22),
(3, 'Charlie', 23);

 INSERT INTO courses (course_id, course_name, student_id) VALUES


(101, 'Math', 1),
(102, 'Science', 2),
(103, 'History', 3),
(104, 'Art', 1);

Selecting the table


 select * from students;
 select * from courses;

Performing a Inner Join


 SELECT students.student_id, students.student_name, courses.course_name
FROM students
INNER JOIN courses ON students.student_id = courses.student_id;
Performing a Union
 SELECT student_name AS name FROM students
UNION
SELECT course_name AS name FROM courses;
Result
The mysql query to create any two tables with common column name and perform join and
union has been done successfully.
OUTPUT:

Students table structure:

courses table structure:

Viewing the contents of ‘students’ table:


Viewing the contents of ‘courses’ table:

Performing inner join:

Performing union:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy