G
G
grigorie19902018-03-18 11:58:16
MySQL
grigorie1990, 2018-03-18 11:58:16

How to query the child of a related table to get the parent's related data as well?

Good afternoon!

CREATE TABLE `users` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
  `login` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
  `email` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
  `password` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
  `admin` TINYINT(1) NULL DEFAULT '0',
  `card` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
  `fuel` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
  `info` TEXT NULL COLLATE 'utf8mb4_unicode_ci',
  `remember_token` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
  `created_at` TIMESTAMP NULL DEFAULT NULL,
  `updated_at` TIMESTAMP NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `users_email_unique` (`email`)
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=8
;

CREATE TABLE `fuelPrices` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `user_id` INT(11) NOT NULL DEFAULT '0',
  `Ai98` VARCHAR(50) NOT NULL DEFAULT '0',
  `JET` VARCHAR(50) NOT NULL DEFAULT '0',
  `Ai95` VARCHAR(50) NOT NULL DEFAULT '0',
  `Ai92` VARCHAR(50) NOT NULL DEFAULT '0',
  `Diesel` VARCHAR(50) NOT NULL DEFAULT '0',
  `created_at` TIMESTAMP NULL DEFAULT NULL,
  `updated_at` TIMESTAMP NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=10
;

I want to make a query to fuelPrices to also get data from the users table eg name, login?
Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question