0% found this document useful (0 votes)
70 views8 pages

CCS110-Activity 3 Module 13-FINALS-PALMA (20230427214727)

The document describes SQL joins, including inner, left, right, and full joins. It provides examples of SQL code to create tables for foods and locations, insert data into the tables, and perform inner, left, right, and full joins on the tables to combine data and return results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views8 pages

CCS110-Activity 3 Module 13-FINALS-PALMA (20230427214727)

The document describes SQL joins, including inner, left, right, and full joins. It provides examples of SQL code to create tables for foods and locations, insert data into the tables, and perform inner, left, right, and full joins on the tables to combine data and return results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PRETEST

1. What is SQL Join?


SQL join is a method used to combine rows from two or more tables based on a related column
between them. A join operation takes two or more tables as input and returns a new table that
combines matching rows from the input tables according to the join condition.
2. What is SQL Inner Join?
Returns only the rows that have matching values in both tables based on the join condition.
3. What is SQL Left Join?
Returns all the rows from the left table and the matching rows from the right table based on the
join condition. If there is no match in the right table, the result will contain null values.
4. What is SQL Right Join?
Returns all the rows from the right table and the matching rows from the left table based on the
join condition. If there is no match in the left table, the result will contain null values.
5. What is SQL Full Join?
Returns all the rows from both tables and fills in null values where there are no matches
between the tables.
POST TEST

Directions: Identify the given statements below.

1. It is a kind of join that joins data from related tables together based on the shared

columns. SQL Join

2. It is used as a logical relationship between two or more tables to extract data from those

tables. SQL Relationship

3. It is used to retrieve data depending on a specific condition from various tables. SQL Where Clause

4. This used to join two tables collectively to generate a new table. SQL Union

5. It is used to fetched and sort data using a SQL query according to one or more columns,

either ascendingly or descending. SQL Order By


SOURCE CODE:

CREATE DATABASE palmarestodb;

USE palmarestodb;

CREATE TABLE Food (

id INT NOT NULL AUTO_INCREMENT,

Name_of_the_Food VARCHAR(255) NOT NULL,

Price INT NOT NULL,

Food_ID INT NOT NULL,

Type_of_the_Food VARCHAR(255) NOT NULL,

PRIMARY KEY (id)

);

CREATE TABLE Location(

id2 INT NOT NULL,

Food_ID INT NOT NULL,

Locations VARCHAR(255) NOT NULL

);

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (1, 'Adobo', 300,


2201, 'Chicken' );

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (2, 'Lasagna', 234,


2202, 'Pasta' );

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (3, 'Kebab', 345,


2203, 'Ground Beef and Chicken');

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (4, 'Peking Duck',


6581, 2204, 'Duck');

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (5, 'Tteok-bokki',


245, 2205, 'Chewy rice cakes');

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (6, 'French Fries',


278, 2206, 'Potato');
INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (7, 'Tonkatsu', 1358,
2207, 'Pork loin');

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (8, 'Pad Thai', 678,


2208, 'Stir fried dry noodles');

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (9, 'Burrito', 386,


2209, 'Chicken');

INSERT INTO Food(id,Name_of_the_Food,Price,Food_ID,Type_of_the_Food) VALUES (11, 'Buttered


Lobster', 3839, 2210, 'Seafood');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (1,2201, 'Philippines');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (2,2202, 'Italy');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (3,2203, 'Turkey');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (4,2204, 'China');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (5,2205, 'South Korea');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (6,2206, 'Belgium');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (7,2207, 'Japan');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (8,2208, 'Thailand');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (9,2209, 'Mexico');

INSERT INTO Location(id2,Food_ID, Locations) VALUES (10,2212, 'Norway');

SELECT * FROM Location;

-- Inner Join

SELECT * FROM Food

INNER JOIN Location ON Food.id = Location.id2;

-- Left Join

SELECT * FROM Food

LEFT JOIN Location ON Food.id = Location.id2;


-- Right Join

SELECT * FROM Food

RIGHT JOIN Location ON Food.id = Location.id2;

-- Full Join (Combination of Inner, Left, and Right Join to see the full results)

SELECT * FROM Food

LEFT JOIN Location ON Food.id = Location.id2

UNION

SELECT * FROM Food

RIGHT JOIN Location ON Food.id = Location.id2

WHERE Food.id IS NULL;

You might also like