I hope I can ask this question in a way that makes some sense as the data itself is not good. However, as it was written in the 1950s, I have no option but to try to make the best of it in trying to bring it into the current century for those of us who need it. Also, Benchmark speed is not an issue as this is run manually and only rarely, and always on my local PC rather than on the live server. The resulting table is then uploaded.
To outline, it is looking in the Models
field in parts_listing
to see any with the ordinal numbers 22ND, 23RD etc. If there are any, then it looks in parts_modelno
to find all that begin with the cardinal number 22, 23 etc. It takes all that match and populates parts_parsed
with the rows in the select statement. It is doing that but it is getting all from parts_modelno
, not just those that match.
For the first query below, it works well but needs multiple copies, one for each of the ordinal and cardinal values of 22ND, 23RD, 24TH, 25TH, 26TH, 54TH
and 22, 23, 24, 25, 26, 54
.
The Models
field being queried in parts_listing contains data that varies considerably and another query has already extracted the bulk of it. For example, 2250-51-52-55-70-71
is a shortcut for 2250, 2251, 2252, 2255, 2270, 2271
and there are others such as these below with each example being in its own row. Those have already been parsed into parts_parsed. Those with BODY (and similar ones with MODEL) are not being parsed properly but that's another issue and not important here.
2662-92; 5462-92
ALL 22ND; 2301-02-13-32
LHD, 2401-02-13; 2501-02-13-31; 2601-02-11; 5400-01-02-11
2201 (BODY 2293)
and quite a few other variations. These codes have been parsed out in an earlier operation and are already in the parsed format other than Models in parts_listing which is the original and from which this is trying to find the ordinals so that the data can be completed with those values. Without this, if there is an ALL 22ND or one or more of the others in the data, none of those entries currently appear and that's what I am trying to fix by running an additional query to do so.
INSERT INTO parts_parsed (pageNo, baseGroup, partID, partNo, modelNo)
SELECT PageNo AS pageNo, BaseGroup AS baseGroup, pl.ID AS partID, PartNo AS partNo, chassisNo AS modelNo
FROM parts_listing pl, parts_modelno pm
WHERE Models LIKE '%22ND%'
AND chassisNo LIKE '22%'
AND BaseGroup NOT IN (SELECT GroupNo FROM parts_reftype WHERE BodyChassis = 1);
Following is what I tried in order to simplify it but it gives an entry for every instance of 22ND, 23RD, 24TH, 25TH, 26TH, 54TH
and 22, 23, 24, 25, 26, 54
rather than just those matching 22ND and 22 and I understand why but I am unsure what to do about it.
INSERT INTO parts_parsed (pageNo, baseGroup, partID, partNo, modelNo)
SELECT PageNo AS pageNo, BaseGroup AS baseGroup, pl.ID AS partID, PartNo AS partNo, chassisNo AS modelNo
FROM parts_listing pl, parts_modelno pm
WHERE Models REGEXP '22ND|23RD|24TH|25TH|26TH|54TH'
AND chassisNo REGEXP '22|23|24|25|26|54'
AND BaseGroup NOT IN (SELECT GroupNo FROM parts_reftype WHERE BodyChassis = 1);
The structure for parts_parsed is below, followed by a small sample of the data (there are over 450k rows).
CREATE TABLE IF NOT EXISTS `parts_parsed` (
`ID` int unsigned NOT NULL AUTO_INCREMENT,
`pageNo` int unsigned NOT NULL,
`baseGroup` int unsigned NOT NULL,
`partID` int unsigned NOT NULL,
`partNo` varchar(20) NOT NULL,
`modelNo` smallint unsigned DEFAULT NULL,
`bodyNo` smallint unsigned DEFAULT NULL,
`isRHD` tinyint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_GENERAL_CI;
ID pageNo baseGroup partID partNo modelNo bodyNo isRHD
1 1 0 1 391906 2201 0
2 1 0 1 391906 2202 0
3 1 0 1 391906 2211 0
4 1 0 1 391906 2220 0
5 1 0 1 391906 2222 0
6 1 0 1 391906 2232 0
7 1 0 1 391906 2240 0
8 1 0 1 391906 2301 0
9 1 0 2 391907 2306 0
10 1 0 2 391907 2326 0
The structure of parts_modelno is below, followed by a small sample of data.
DROP TABLE IF EXISTS `parts_modelno`;
CREATE TABLE IF NOT EXISTS `parts_modelno` (
`ID` smallint unsigned NOT NULL AUTO_INCREMENT,
`seriesYear` varchar(8) DEFAULT NULL,
`bodyNo` varchar(8) DEFAULT NULL,
`chassisNo` varchar(8) DEFAULT NULL,
`engineNo` varchar(8) DEFAULT NULL,
`modelDesc` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8MB4_GENERAL_CI;;
ID seriesYear bodyNo chassisNo
1 1948-49 2213 2213
2 1948-49 2250 2226
3 1948-49 2251 2226
4 1948-49 2252 2206
5 1948-49 2255 2206
26 1949-50 2365 2301
27 1949-50 2372 2302
28 1949-50 2375 2302
29 1949-50 2379 2332
30 1949-50 2382 2302
And finally as requested, here is the structure of parts_listing followed by a very short sample selected at random.
DROP TABLE IF EXISTS `parts_listing`;
CREATE TABLE IF NOT EXISTS `parts_listing` (
`ID` int unsigned NOT NULL AUTO_INCREMENT,
`BaseGroup` int unsigned DEFAULT NULL,
`GroupNumber` varchar(20) DEFAULT NULL,
`BaseName` varchar(50) DEFAULT NULL,
`GroupName` varchar(50) DEFAULT NULL,
`Name` varchar(100) DEFAULT NULL,
`PartNo` varchar(30) DEFAULT NULL,
`Models` varchar(255) DEFAULT NULL,
`Description` varchar(255) DEFAULT NULL,
`Quantity` smallint unsigned DEFAULT NULL,
`PageNo` int DEFAULT NULL,
`SubPage` varchar(5) DEFAULT NULL,
`RevDate` int DEFAULT NULL,
`Edition` varchar(50) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_GENERAL_CI;
ID BaseGroup GroupNumber BaseName GroupName Name PartNo Models Description Quantity PageNo SubPage RevDate Edition
13570 30 30.46796 BODY DOORS-DOOR REAR TRIM PANEL ASSY "SPECIFY TRIM SET NO" 453674 5450-51 RIGHT, SET 50-52 1 402 -490665600 48-54
1850 3 3.236 CLUTCH AND TRANSMISSION TRANSMISSION FLANGE-DRIVING SHAFT UNIVERSAL JOINT 302868 2213-20-22-26; 2313 1 58 -490665600 48-54
16314 30 30.874934 BODY RADIATOR GRILLE AND SPLASHER BRACKET-RAD SIDE SPLASHER BRACE FRAME G120370 2469; 2579; ALL 26TH; 54TH NUT 7/16-20 2 469 -490665600 48-54
14633 30 30.666983 BODY ELECTRICAL-ROOF LIGHT GROMMET-ROOF LIGHT CABLE 403834 2280-86 1 423 -504921600 48-54
12273 30 30.34395 BODY DOORS-DOOR FRONT MOULDING-TRIM PANEL 442793 2677-79-97; 5467-97 INTERMEDIATE, LOWER, RIGHT 1 369 -490665600 48-54\
Additional examples of Models
can be found here.