Hejsa.
Er der evt. nogen der kan hjælpe mig med at få lavet en sql, så jeg får navne på klubberne en spiller er tilmeldt?
Lige nu får jeg den ud med spillerens navn for hver klub den finder.
- SELECT persons.givenName, clubs.name FROM persons, clubs, persons_has_clubs WHERE persons.id = persons_has_clubs.persons_id AND persons_has_clubs.clubs_id = clubs.id
SQL dump fra db uden data
- -- MySQL Script generated by MySQL Workbench
- -- Thu Jun 9 15:41:04 2016
- -- Model: New Model Version: 1.0
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-
- -- -----------------------------------------------------
- -- Schema superliga
- -- -----------------------------------------------------
- CREATE SCHEMA IF NOT EXISTS `superliga` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
- USE `superliga` ;
-
- -- -----------------------------------------------------
- -- Table `superliga`.`clubs`
- -- -----------------------------------------------------
- CREATE TABLE IF NOT EXISTS `superliga`.`clubs` (
- `id` INT NOT NULL AUTO_INCREMENT,
- `name` VARCHAR(100) NOT NULL,
- `streetAddress` VARCHAR(100) NOT NULL,
- `postalCode` INT NOT NULL,
- `addressLocality` VARCHAR(30) NOT NULL,
- `addressCountry` VARCHAR(45) NOT NULL,
- `logo` VARCHAR(100) NOT NULL,
- `url` VARCHAR(150) NOT NULL,
- PRIMARY KEY (`id`))
- ENGINE = InnoDB;
-
-
- -- -----------------------------------------------------
- -- Table `superliga`.`persons`
- -- -----------------------------------------------------
- CREATE TABLE IF NOT EXISTS `superliga`.`persons` (
- `id` INT NOT NULL AUTO_INCREMENT,
- `givenName` VARCHAR(100) NOT NULL,
- `familyName` VARCHAR(50) NOT NULL,
- `birthDate` VARCHAR(50) NOT NULL,
- `deathDate` VARCHAR(45) NULL,
- `image` VARCHAR(100) NULL,
- `url` VARCHAR(150) NULL,
- `type` ENUM('coach','player','staff') NOT NULL,
- PRIMARY KEY (`id`))
- ENGINE = InnoDB;
-
-
- -- -----------------------------------------------------
- -- Table `superliga`.`persons_has_clubs`
- -- -----------------------------------------------------
- CREATE TABLE IF NOT EXISTS `superliga`.`persons_has_clubs` (
- `persons_id` INT NOT NULL,
- `clubs_id` INT NOT NULL,
- PRIMARY KEY (`persons_id`, `clubs_id`),
- INDEX `fk_persons_has_clubs_clubs1_idx` (`clubs_id` ASC),
- INDEX `fk_persons_has_clubs_persons_idx` (`persons_id` ASC),
- CONSTRAINT `fk_persons_has_clubs_persons`
- FOREIGN KEY (`persons_id`)
- REFERENCES `superliga`.`persons` (`id`)
- ON DELETE NO ACTION
- ON UPDATE NO ACTION,
- CONSTRAINT `fk_persons_has_clubs_clubs1`
- FOREIGN KEY (`clubs_id`)
- REFERENCES `superliga`.`clubs` (`id`)
- ON DELETE NO ACTION
- ON UPDATE NO ACTION)
- ENGINE = InnoDB;
-
-
- SET SQL_MODE=@OLD_SQL_MODE;
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;