I have a Status data inside a table that has 3 possible states (active, inactive, unknown). Similar to this one , I want to make the Status only accept numbers (1,2,3) and then convert to the 3 possible states when displaying the table. I've tried using FK for this and reference the Status data to the Status table but I don't know how to 'link' between the two so that when displaying the table, instead of displaying numbers, it displays the Status in words that corresponds to the number it stores. I also thought about using view and join but, again, I don't have any clue.
DROP TABLE IF EXISTS student_data;
DROP TABLE IF EXISTS Major;
DROP TABLE IF EXISTS Academic_Status;
CREATE TABLE Major(
Id INT PRIMARY KEY,
Major VARCHAR(35) NOT NULL UNIQUE
);
CREATE TABLE Academic_Status(
Id SERIAL,
Academic_Status VARCHAR(15) NOT NULL UNIQUE
);
INSERT INTO Academic_Status (Academic_Status) VALUES
('Inactive'), ('Active'), ('Unknown');
CREATE TABLE student_data (
Id SERIAL,
Name VARCHAR ( 50 ) NOT NULL,
NPM CHAR ( 10 ) NOT NULL UNIQUE,
Date_of_Birth DATE NOT NULL,
Major VARCHAR ( 35 ) NOT NULL,
Academic_Status_ID INT REFERENCES Academic_Status(Id)
);
INSERT INTO student_data (Name, NPM, Date_of_Birth, Major, Academic_Status_ID) VALUES
('Fadhilah Akbar Suherman', '1906355577', '2001-05-17', 'Computer Enginnering', 2),
('Evans Hebert', '1906355367', '2001-03-07', 'Electrical Enginnering', 2),
('Muhammad Hadi', '1906355189', '2001-05-21', 'Mechanical Enginnering', 3),
('Ronald Grant', '1906355235', '2001-01-12', 'Chemical Enginnering', 1),
('Theodorus Lucas', '1906354594', '2001-11-23', 'Computer Enginnering', 2),
('Yusuf Agung', '1906355342', '2001-08-25', 'Electrical Enginnering', 1);
SELECT * FROM student_data
INNER JOIN Academic_Status ON student_data.Academic_Status_ID = Academic_Status.Id;
INSERT INTO student_data (Name, NPM, Date_of_Birth, Major, Academic_Status_ID) VALUES
('Muhammad Rafly Yanuar', '2006468661', '2002-01-17', 'Computer Enginnering', 2);