Closed sc4n1a471 closed 2 years ago
INSERT INTO `brands` (`brand`) VALUES ('BMW');
INSERT INTO `brands` (`brand`) VALUES ('Tesla');
INSERT INTO `brands` (`brand`) VALUES ('Audi');
INSERT INTO `brands` (`brand`) VALUES ('Mercedes-Benz');
INSERT INTO `brands` (`brand`) VALUES ('Porsche');
INSERT INTO `brands` (`brand`) VALUES ('Ford');
INSERT INTO `brands` (`brand`) VALUES ('Hyundai');
INSERT INTO `brands` (`brand`) VALUES ('Lexus');
INSERT INTO `brands` (`brand`) VALUES ('Maserati');
INSERT INTO `brands` (`brand`) VALUES ('Volkswagen');
INSERT INTO `brands` (`brand`) VALUES ('Bentley');
INSERT INTO `brands` (`brand`) VALUES ('Mazda');
INSERT INTO `brands` (`brand`) VALUES ('Alfa Romeo');
INSERT INTO `brands` (`brand`) VALUES ('Honda');
INSERT INTO `brands` (`brand`) VALUES ('Nissan');
INSERT INTO `brands` (`brand`) VALUES ('Skoda');
INSERT INTO `brands` (`brand`) VALUES ('Range Rover');
INSERT INTO `brands` (`brand`) VALUES ('Kia');
INSERT INTO `brands` (`brand`) VALUES ('Ferrari');
Update table1's brand_ids with brands' brand_ids
UPDATE table1 INNER JOIN brands ON table1.brand = brands.brand SET table1.brand_id = brands.brand_id;
ALTER TABLE `table1` ADD CONSTRAINT `br` FOREIGN KEY (`brand_id`) REFERENCES `brands`(`brand_id`) ON DELETE NO ACTION ON UPDATE CASCADE;
SELECT table1.license_plate, brands.brand, table1.model, table1.codename, table1.year, table1.comment, table1.is_new FROM table1 INNER JOIN brands ON table1.brand_id = brands.brand_id ORDER BY license_plate;
Move brands to individual table