I am learning MySQL JOINs now and something factor I wish to know is how you can JOIN two child tables with one father table.

Within this situation, the totally this:

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 have placed these values:

INSERT INTO `mydb`.`objetos` VALUES (NULL, 'Cadeira XTT', 'Quê?', SHA1(CONCAT(3913123612,'one@gmail.com')));
INSERT INTO `mydb`.`objetos` VALUES (NULL, 'Mesa TTX', 'Hein?', SHA1(CONCAT(4313123612,'two@gmail.com')));
INSERT INTO `mydb`.`objetos` VALUES (NULL, 'Prédio TT', 'Hein?', SHA1(CONCAT(73358847000116,'buzz@gmail.com')));

INSERT INTO `mydb`.`civis` VALUES (NULL, 'One', 3913123612, 'one@gmail.com', SHA1(CONCAT(3913123612,'one@gmail.com')));
INSERT INTO `mydb`.`civis` VALUES (NULL, 'Two', 4313123612, 'two@gmail.com', SHA1(CONCAT(4313123612,'two@gmail.com')));

INSERT INTO `mydb`.`empresas` VALUES(NULL, 'Buzz', 73358847000116, 'buzz@gmail.com', 33270743, SHA1(CONCAT(73358847000116,'buzz@gmail.com')));

But you will find some problems when I wish to retrieve the recorded data. Natural JOIN does not act as the expected, taking just the rows with similar token and that i can't for this:

SELECT * 
FROM objetos 

JOIN civis 
ON(objetos.token_dono = civis.token) 

JOIN empresas 
ON(objetos.token_dono = empresas.token)

To list out all "objetos" from database with correct informations. But as I have examined it not work.

If a person can provide us a light with one of these problems I'm going to be grateful.