I am about to setup a sql db, not decided yet for mysql, mariadb or postgresql. But before that I have set up my sql script to create the tables I need.
CREATE TABLE `teams` (
`team_id` INT NOT NULL AUTO_INCREMENT,
`team_name` VARCHAR(255) NOT NULL UNIQUE,
`team_payed` ENUM('no', 'yes'),
`team_members` JSON,
`timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`team_id`)
);
CREATE TABLE `judges` (
`judge_id` INT NOT NULL AUTO_INCREMENT,
`judge_name` VARCHAR(255) NOT NULL UNIQUE,
`active` ENUM('no', 'yes'),
`timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`judge_id`)
);
CREATE TABLE `competition` (
`comp_id` INT NOT NULL AUTO_INCREMENT,
`comp_year` YEAR(4) NOT NULL UNIQUE,
`comp_branches` JSON, --branch1, branch2, branch3
`comp_name` varchar(255) NOT NULL UNIQUE,
`timestamp` DATETIME(255) TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`comp_id`)
);
CREATE TABLE `championship` (
`champ_id` INT NOT NULL AUTO_INCREMENT,
`team_id` INT NOT NULL,
`judge_id` INT NOT NULL,
`comp_id` INT NOT NULL,
`comp_score` INT NOT NULL,
`comp_branch` VARCHAR(255) NOT NULL, --SELECT comp_branches FROM competition WHERE comp_id = 1,2,3
PRIMARY KEY (`champ_id`)
);
ALTER TABLE `championship` ADD CONSTRAINT `championship_fk0` FOREIGN KEY (`team_id`) REFERENCES `teams`(`team_id`);
ALTER TABLE `championship` ADD CONSTRAINT `championship_fk1` FOREIGN KEY (`judge_id`) REFERENCES `judges`(`judge_id`);
ALTER TABLE `championship` ADD CONSTRAINT `championship_fk2` FOREIGN KEY (`comp_id`) REFERENCES `competition`(`comp_id`);
ALTER TABLE `championship` ADD CONSTRAINT `championship_fk3` FOREIGN KEY (`comp_branch`) REFERENCES `competition`(`comp_branches`);
First I need help with a sanity check, can you without me see what I am setting up here? Second, the thing I am struggeling with now is an SELECT.
I want to be able to SELECT from championship table, let me show what I want: Judge GREEN gave team YELLOW 10 points How do I get this SELECT... that is my question.