@Speakermen

Правильно ли делать много Joins?

Не знаю правильно ли так делать. Может их отдельно выводить ну тогда запросов будет больше( Если RESTfull будет?

SELECT motherboards.id,
	   chipsets.chipset_name,
       brends.brend_name,
       series.series_name,
       connectors.connector_name,
       motherboards.motherboard_name,
       motherboards.motherboard_image FROM asus.motherboards 
			JOIN asus.chipsets ON motherboards.chipset_id = chipsets.id
            JOIN asus.brends ON motherboards.brend_id = brends.id
            JOIN asus.series ON motherboards.series_id = series.id
            JOIN asus.connectors ON motherboards.connector_id = connectors.id ORDER BY motherboards.id ASC;


spoiler

DROP DATABASE `asus`;
CREATE DATABASE `asus`;
USE `asus`;

CREATE TABLE asus.chipsets
(
   id INT UNSIGNED AUTO_INCREMENT NOT NULL,
   chipset_name VARCHAR(255),
   PRIMARY KEY(`id`)
);

CREATE TABLE asus.brends
(
   `id` INT UNSIGNED AUTO_INCREMENT NOT NULL,
   `brend_name` VARCHAR(30),
   PRIMARY KEY(`id`)
);

CREATE TABLE asus.series
(
   `id` INT UNSIGNED AUTO_INCREMENT NOT NULL,
   `series_name` VARCHAR(255),
   PRIMARY KEY(`id`)
);

CREATE TABLE asus.connectors
(
   `id` INT UNSIGNED AUTO_INCREMENT NOT NULL,
   `connector_name` VARCHAR(255),
   PRIMARY KEY(`id`)
);

CREATE TABLE asus.motherboards
(
   id INT UNSIGNED AUTO_INCREMENT NOT NULL,
   `chipset_id` INT UNSIGNED NOT NULL,
   `brend_id` INT UNSIGNED NOT NULL,
   `series_id` INT UNSIGNED NOT NULL,
   `connector_id` INT UNSIGNED NOT NULL,
   `motherboard_name` VARCHAR(255) NOT NULL,
   `motherboard_image` VARCHAR(255) NOT NULL,
	   FOREIGN KEY(`chipset_id`) REFERENCES chipsets(`id`),
	   FOREIGN KEY(`brend_id`) REFERENCES brends(`id`),
	   FOREIGN KEY(`series_id`) REFERENCES series(`id`),
	   FOREIGN KEY(`connector_id`) REFERENCES connectors(`id`),
   PRIMARY KEY(`id`)
);

INSERT INTO asus.chipsets(`chipset_name`) VALUES 
	('Intel B560'),
    ('Intel Z590');
    
INSERT INTO asus.brends(`brend_name`) VALUES 
	('Intel'),
	('AMD');
    
INSERT INTO asus.series(`series_name`) VALUES 
	('PRIME'),
    ('ProArt'),
    ('ROG - Republic of Gamers'),
	('TUF Gaming');
    
INSERT INTO asus.connectors(`connector_name`) VALUES 
	('LGA 1200'),
	('AM4');
    
INSERT INTO asus.motherboards
(
	`chipset_id`,
    `brend_id`, 
    `series_id`, 
    `connector_id`,
    `motherboard_name`, 
    `motherboard_image`
) 
VALUES 
	(2, 1, 1, 1, 'PRIME Z590M-PLUS', 'https://dlcdnwebimgs.asus.com/gain/109a7d9b-f938-48b5-a8fa-ec1b73210558/w185'),
    (2, 1, 1, 1, 'PRIME Z590M-PLUS', 'https://dlcdnwebimgs.asus.com/gain/17aff855-1b28-4a7d-8ca1-9aaf8418b723/w185'),
    (2, 1, 1, 1, 'PRIME Z590-A', 'https://dlcdnwebimgs.asus.com/gain/276acda5-c2eb-4d3e-8b35-844eed31d025/w185'),
    (1, 1, 1, 1, 'PRIME B560-PLUS', 'https://dlcdnwebimgs.asus.com/gain/f8c4b5c6-002c-4b97-8cf5-13a2fb63ea41/w185');
    
SELECT motherboards.id,
	   chipsets.chipset_name,
       brends.brend_name,
       series.series_name,
       connectors.connector_name,
       motherboards.motherboard_name,
       motherboards.motherboard_image FROM asus.motherboards 
			JOIN asus.chipsets ON motherboards.chipset_id = chipsets.id
            JOIN asus.brends ON motherboards.brend_id = brends.id
            JOIN asus.series ON motherboards.series_id = series.id
            JOIN asus.connectors ON motherboards.connector_id = connectors.id ORDER BY motherboards.id ASC;

  • Вопрос задан
  • 73 просмотра
Пригласить эксперта
Ответы на вопрос 1
@VitalyChaikin
Надеюсь имеется ввиду LEFT JOIN в противном случае легко получите миллиард записей
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы