خرید بک لینک
I have this table:

Code:

CREATE TABLE `ksuite2_list` (
  `ksuite2_list_id` int(11) NOT NULL,
  `Alientech_Category` varchar(50) DEFAULT NULL,
  `Brand` varchar(150) DEFAULT NULL,
  `Model` varchar(255) DEFAULT NULL,
  `Type` varchar(50) DEFAULT NULL,
  `Version` varchar(50) DEFAULT NULL,
  `Engine_Code` varchar(50) DEFAULT NULL,
  `KW` varchar(5) DEFAULT NULL,
  `HP` varchar(5) DEFAULT NULL,
  `Fuel` varchar(12) DEFAULT NULL,
  `MY` int(11) NOT NULL,
  `ECU_Brand` varchar(25) DEFAULT NULL,
  `ECU_Version` varchar(25) DEFAULT NULL,
  `KESSv2_Protocol` int(11) NOT NULL,
  `K-TAG_Group` varchar(25) DEFAULT NULL,
  `K-TAG_Protocol` int(11) NOT NULL
) ENGINE=IoDB DEFAULT CHARSET=utf8;

I am just trying to retrieve the Brands and Models and insert them into a new table:

I have created these tables for the brands & models:
Code:

CREATE TABLE `vehicle_brands` (
  `brand_id` int(11) NOT NULL,
  `brand_name` varchar(255) NOT NULL
) ENGINE=IoDB DEFAULT CHARSET=utf8;

Code:

CREATE TABLE `vehicle_models` (
  `model_id` int(10) NOT NULL,
  `model_brand` int(10) NOT NULL,
  `model_name` varchar(255) NOT NULL
) ENGINE=IoDB DEFAULT CHARSET=utf8;

and ran this query:
Code:

INSERT INTO vehicle_brands (brand_name) SELECT `Brand` FROM `ksuite2_list` GROUP BY Brand ORDER BY Brand
So now I have all the brands, but no models - YET...

But how can I retrieve the Models and allocate them there correct brand id? As the brand is currently text and not there new ID, in a single query? or do I need to take there brand name first then run a load of UPDATE queries?

I have tried INNER_JOIN but that doesn't seem to work?

Any help or advice would be gratefully received?

برچسب: نویسنده: آیلین رضوانی تاريخ: پنجشنبه 5 بهمن 1396 ساعت: 8:47

صفحه بندی