我现在学习MySQL JOINs,我想知道的是,我是如何去日本女学生会看两个孩子桌子,一个是父亲。
在本案中,问题是:
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 ;
DROP SCHEMA IF EXISTS `test` ;
CREATE SCHEMA IF NOT EXISTS `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `test`;
CREATE TABLE IF NOT EXISTS `test`.`objetos` (
`idobjetos` INT(11) NOT NULL AUTO_INCREMENT ,
`modelo` VARCHAR(45) NULL DEFAULT NULL ,
`descricao` VARCHAR(45) NULL DEFAULT NULL ,
`token_dono` VARCHAR(41) NOT NULL ,
PRIMARY KEY (`idobjetos`, `token_dono`) ,
INDEX `token_dono` (`token_dono` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
CREATE TABLE IF NOT EXISTS `test`.`empresas` (
`idempresa` INT(11) NULL DEFAULT NULL AUTO_INCREMENT ,
`nome` VARCHAR(45) NULL DEFAULT NULL ,
`cnpj` VARCHAR(45) NULL DEFAULT NULL ,
`email` VARCHAR(45) NULL DEFAULT NULL ,
`telefone` VARCHAR(45) NULL DEFAULT NULL ,
`token` VARCHAR(41) NOT NULL ,
PRIMARY KEY (`idempresa`, `token`) ,
INDEX `token_empresa` (`token` ASC) ,
UNIQUE INDEX `cnpj_UNIQUE` (`cnpj` ASC) ,
UNIQUE INDEX `email_UNIQUE` (`email` ASC) ,
UNIQUE INDEX `telefone_UNIQUE` (`telefone` ASC) ,
CONSTRAINT `token_empresa`
FOREIGN KEY (`token` )
REFERENCES `test`.`objetos` (`token_dono` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
CREATE TABLE IF NOT EXISTS `test`.`civis` (
`idcivil` INT(11) NOT NULL AUTO_INCREMENT ,
`nome` VARCHAR(45) NULL DEFAULT NULL ,
`cpf` VARCHAR(45) NULL DEFAULT NULL ,
`email` VARCHAR(45) NULL DEFAULT NULL ,
`token` VARCHAR(41) NOT NULL ,
PRIMARY KEY (`idcivil`, `token`) ,
INDEX `token_civil` (`token` ASC) ,
UNIQUE INDEX `cpf_UNIQUE` (`cpf` ASC) ,
UNIQUE INDEX `email_UNIQUE` (`email` ASC) ,
CONSTRAINT `token_civil`
FOREIGN KEY (`token` )
REFERENCES `test`.`objetos` (`token_dono` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
CREATE TABLE IF NOT EXISTS `test`.`an_users` (
`id` INT(11) NULL DEFAULT NULL AUTO_INCREMENT ,
`usuario` VARCHAR(45) NULL DEFAULT NULL ,
`senha` VARCHAR(45) NULL DEFAULT NULL ,
`cod_usuario` INT(11) NOT NULL ,
PRIMARY KEY (`id`, `cod_usuario`) ,
INDEX `cod_usuario_fk` (`cod_usuario` ASC) ,
CONSTRAINT `cod_usuario_fk`
FOREIGN KEY (`cod_usuario` )
REFERENCES `test`.`empresas` (`idempresa` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
And I ve inserted these values:
INSERT INTO `mydb`.`objetos` VALUES (NULL, Cadeira XTT , Quê? , SHA1(CONCAT(3913123612, [email protected] )));
INSERT INTO `mydb`.`objetos` VALUES (NULL, Mesa TTX , Hein? , SHA1(CONCAT(4313123612, [email protected] )));
INSERT INTO `mydb`.`objetos` VALUES (NULL, Prédio TT , Hein? , SHA1(CONCAT(73358847000116, [email protected] )));
INSERT INTO `mydb`.`civis` VALUES (NULL, One , 3913123612, [email protected] , SHA1(CONCAT(3913123612, [email protected] )));
INSERT INTO `mydb`.`civis` VALUES (NULL, Two , 4313123612, [email protected] , SHA1(CONCAT(4313123612, [email protected] )));
INSERT INTO `mydb`.`empresas` VALUES(NULL, Buzz , 73358847000116, [email protected] , 33270743, SHA1(CONCAT(73358847000116, [email protected] )));
但是,在我希望检索记录的数据时,有一些问题。 北大西洋渔业组织与预期的工作不一样,只吸收有相同症状的浏览器,我可以这样做:
SELECT *
FROM objetos
JOIN civis
ON(objetos.token_dono = civis.token)
JOIN empresas
ON(objetos.token_dono = empresas.token)
从数据库中列出所有“objetos”的准确信息。 但是,随着我对它进行测试,它不会奏效。
如果有人能够让我了解这些问题,我将不胜感激。