Variable or Inner Select in Like Operator? - mysql

I need to make some updates in a table and I want to update the some values based on a like statement. e.g Like '%0010030 a.jpg'
The 0010030 is an example of a product code in my database and it reaches a specific number till now.
I would like to make an for loop to make the changes of i=0010030 to the number I need, i++.
I not sure is it works but i am trying to set it like this '%Variable_Name a.jpg'
In order do it automatically.
I actually have a list of sku/ids that i need to check
Any help or ideas?
What i have:
Insert Ignore Into prefix_virtuemart_product_medias(virtuemart_product_id,virtuemart_media_id,ordering) VALUES (
(Select nprefix_virtuemart_products.virtuemart_product_id from prefix_virtuemart_products where prefix_virtuemart_products.product_sku LIKE '0010030'),
(Select prefix_virtuemart_medias.virtuemart_media_id from prefix_virtuemart_medias
where prefix_virtuemart_medias.file_url LIKE '%0010030 a.jpg' or prefix_virtuemart_medias.file_url LIKE '%0010030 A.jpg'),5);
But i need to automatically change the LIKE parameter from a column that has all of these product codes (it's the product_sku field)
Tables dump with sample data:
CREATE TABLE IF NOT EXISTS `prefix_virtuemart_product_medias` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`virtuemart_product_id` int(1) unsigned NOT NULL DEFAULT '0',
`virtuemart_media_id` int(1) unsigned NOT NULL DEFAULT '0',
`ordering` int(2) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `i_virtuemart_product_id` (`virtuemart_product_id`,`virtuemart_media_id`),
KEY `i_ordering` (`ordering`)
) ENGINE=MyISAM AUTO_INCREMENT=3443 DEFAULT CHARSET=utf8;
-- Dumping data for table virtuemart_product_medias: 1.496 rows
/*!40000 ALTER TABLE `prefix_virtuemart_product_medias` DISABLE KEYS */;
INSERT INTO `prefix_virtuemart_product_medias` (`id`, `virtuemart_product_id`, `virtuemart_media_id`, `ordering`) VALUES
(1909, 2849, 12595, 1),
(1910, 2849, 12596, 1),
(1911, 2849, 12597, 1),
-- Dumping structure for table virtuemart_medias
CREATE TABLE IF NOT EXISTS `prefix_virtuemart_medias` (
`virtuemart_media_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`virtuemart_vendor_id` smallint(1) NOT NULL DEFAULT '1',
`file_title` char(126) NOT NULL DEFAULT '',
`file_description` char(254) NOT NULL DEFAULT '',
`file_meta` char(254) NOT NULL DEFAULT '',
`file_mimetype` char(64) NOT NULL DEFAULT '',
`file_type` char(32) NOT NULL DEFAULT '',
`file_url` varchar(900) NOT NULL DEFAULT '',
`file_url_thumb` varchar(900) NOT NULL DEFAULT '',
`file_is_product_image` tinyint(1) NOT NULL DEFAULT '0',
`file_is_downloadable` tinyint(1) NOT NULL DEFAULT '0',
`file_is_forSale` tinyint(1) NOT NULL DEFAULT '0',
`file_params` varchar(17500) DEFAULT NULL,
`file_lang` varchar(500) NOT NULL,
`shared` tinyint(1) NOT NULL DEFAULT '0',
`published` tinyint(1) NOT NULL DEFAULT '1',
`created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` int(11) NOT NULL DEFAULT '0',
`modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` int(11) NOT NULL DEFAULT '0',
`locked_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`locked_by` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`virtuemart_media_id`),
KEY `i_virtuemart_vendor_id` (`virtuemart_vendor_id`),
KEY `i_published` (`published`),
KEY `i_shared` (`shared`)
) ENGINE=MyISAM AUTO_INCREMENT=16811 DEFAULT CHARSET=utf8 COMMENT='Additional Images and Files which are assigned to products';
-- Dumping data for table virtuemart_medias: 4.216 rows
/*!40000 ALTER TABLE `prefix_virtuemart_medias` DISABLE KEYS */;
INSERT INTO `prefix_virtuemart_medias` (`virtuemart_media_id`, `virtuemart_vendor_id`, `file_title`, `file_description`, `file_meta`, `file_mimetype`, `file_type`, `file_url`, `file_url_thumb`, `file_is_product_image`, `file_is_downloadable`, `file_is_forSale`, `file_params`, `file_lang`, `shared`, `published`, `created_on`, `created_by`, `modified_on`, `modified_by`, `locked_on`, `locked_by`) VALUES
(12595, 1, '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', 'image/jpeg', 'product', 'images/stories/virtuemart/product/0010030 a.jpg', '', 0, 0, 0, '', '', 0, 1, '2014-05-10 06:06:44', 466, '2014-05-23 14:09:03', 466, '0000-00-00 00:00:00', 0),
(12596, 1, '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', 'image/jpeg', 'product', 'images/stories/virtuemart/product/0010030 b.jpg', '', 0, 0, 0, '', '', 0, 1, '2014-05-10 06:06:44', 466, '2014-05-23 14:09:03', 466, '0000-00-00 00:00:00', 0),
(12597, 1, '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', 'image/jpeg', 'product', 'images/stories/virtuemart/product/0010030 c.jpg', '', 0, 0, 0, '', '', 0, 1, '2014-05-10 06:06:44', 466, '2014-05-23 14:09:03', 466, '0000-00-00 00:00:00', 0),
(12598, 1, '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', '0010030 MIZA DAIHATSU', 'image/jpeg', 'product', 'images/stories/virtuemart/product/0010030 d.jpg', '', 0, 0, 0, '', '', 0, 1, '2014-05-10 06:06:44', 466, '2014-05-23 14:09:03', 466, '0000-00-00 00:00:00', 0);
-- Dumping structure for table prefix_virtuemart_products
CREATE TABLE IF NOT EXISTS `prefix_virtuemart_products` (
`virtuemart_product_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`virtuemart_vendor_id` smallint(1) unsigned NOT NULL DEFAULT '1',
`product_parent_id` int(1) unsigned NOT NULL DEFAULT '0',
`product_sku` char(64) DEFAULT NULL,
`product_gtin` char(64) DEFAULT NULL,
`product_mpn` char(64) DEFAULT NULL,
`product_weight` decimal(10,4) DEFAULT NULL,
`product_weight_uom` char(7) DEFAULT NULL,
`product_length` decimal(10,4) DEFAULT NULL,
`product_width` decimal(10,4) DEFAULT NULL,
`product_height` decimal(10,4) DEFAULT NULL,
`product_lwh_uom` char(7) DEFAULT NULL,
`product_url` char(255) DEFAULT NULL,
`product_in_stock` int(1) NOT NULL DEFAULT '0',
`product_ordered` int(1) NOT NULL DEFAULT '0',
`low_stock_notification` int(1) unsigned NOT NULL DEFAULT '0',
`product_available_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`product_availability` char(32) DEFAULT NULL,
`product_special` tinyint(1) DEFAULT NULL,
`product_sales` int(1) unsigned NOT NULL DEFAULT '0',
`product_unit` varchar(8) DEFAULT NULL,
`product_packaging` decimal(8,4) unsigned DEFAULT NULL,
`product_params` varchar(2000) DEFAULT NULL,
`hits` int(11) unsigned DEFAULT NULL,
`intnotes` varchar(18000) DEFAULT NULL,
`metarobot` varchar(400) DEFAULT NULL,
`metaauthor` varchar(400) DEFAULT NULL,
`layout` char(16) DEFAULT NULL,
`published` tinyint(1) DEFAULT NULL,
`pordering` mediumint(2) unsigned NOT NULL DEFAULT '0',
`created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` int(11) NOT NULL DEFAULT '0',
`modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` int(11) NOT NULL DEFAULT '0',
`locked_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`locked_by` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`virtuemart_product_id`),
KEY `idx_product_virtuemart_vendor_id` (`virtuemart_vendor_id`),
KEY `idx_product_product_parent_id` (`product_parent_id`),
KEY `i_product_special` (`product_special`),
KEY `i_published` (`published`),
KEY `i_pordering` (`pordering`)
) ENGINE=MyISAM AUTO_INCREMENT=3809 DEFAULT CHARSET=utf8 COMMENT='All products are stored here.';
-- Dumping data for table kontosdb.prefix_virtuemart_products: 960 rows
/*!40000 ALTER TABLE `prefix_virtuemart_products` DISABLE KEYS */;
INSERT INTO `prefix_virtuemart_products` (`virtuemart_product_id`, `virtuemart_vendor_id`, `product_parent_id`, `product_sku`, `product_gtin`, `product_mpn`, `product_weight`, `product_weight_uom`, `product_length`, `product_width`, `product_height`, `product_lwh_uom`, `product_url`, `product_in_stock`, `product_ordered`, `low_stock_notification`, `product_available_date`, `product_availability`, `product_special`, `product_sales`, `product_unit`, `product_packaging`, `product_params`, `hits`, `intnotes`, `metarobot`, `metaauthor`, `layout`, `published`, `pordering`, `created_on`, `created_by`, `modified_on`, `modified_by`, `locked_on`, `locked_by`) VALUES
(2849, 1, 0, '0100300', '', '', 0.0000, 'KG', 0.0000, 0.0000, 0.0000, 'CM', '', 0, 0, 0, '2010-05-17 00:00:00', '', 0, 0, 'KG', NULL, 'min_order_level=""|max_order_level=""|step_order_level=""|product_box=""|', NULL, '', '', '', '0', 1, 0, '2010-05-17 12:46:52', 466, '2014-05-16 06:35:16', 466, '0000-00-00 00:00:00', 0),
(2850, 1, 0, '0100623', NULL, NULL, 0.0000, 'KG', 0.0000, 0.0000, 0.0000, 'CM', '', 0, 0, 0, '2010-05-28 00:00:00', '', 0, 0, 'Τεμάχιο', NULL, 'min_order_level=null|max_order_level=null|step_order_level=null|product_box=null|', NULL, '', '', '', '', 1, 0, '2010-05-28 12:40:19', 466, '2014-05-10 06:06:44', 466, '0000-00-00 00:00:00', 0),
(2851, 1, 0, '0100630', NULL, NULL, 0.0000, 'KG', 0.0000, 0.0000, 0.0000, 'CM', '', 0, 0, 0, '2010-05-28 00:00:00', '', 0, 0, 'Τεμάχιο', NULL, 'min_order_level=null|max_order_level=null|step_order_level=null|product_box=null|', NULL, '', '', '', '', 1, 0, '2010-05-28 12:47:16', 466, '2014-05-10 06:06:44', 466, '0000-00-00 00:00:00', 0);

I'm not sure I understand what you are having trouble with. With the following give you the results you expect?
SELECT
nprefix_virtuemart_products.virtuemart_product_id,
pvm.virtuemart_media_id,
5
FROM
prefix_virtuemart_products pvp
INNER JOIN prefix_virtuemart_medias pvm ON pvm.file_url LIKE CONCAT('%', pvp.product_sku, ' a.jpg')
OR pvm.file_url LIKE CONCAT('%', pvp.product_sku, ' A.jpg');
For this to work the subquery can only return one row, I don't know what your data looks like, so that might not be the case.

Related

How to make slow MySQL query run faster

I have this query that often shows me "error code 2013. lost connection to mysql query" whenever I run it:
DROP TABLE IF EXISTS elogbook_get_boardid;
CREATE TABLE elogbook_get_boardid AS
(SELECT DISTINCT `LOTID`,
`Board_ID`,
`Serial_Number`,
coalesce(CASE
WHEN A.`Serial_Number` = B.`board_sn` THEN 'In Use'
ELSE A.`status`
END, '') AS `Status`,
coalesce(B.`LOT_LOCATION`, '') AS `chamber`,
coalesce(B.`created_date`, '') AS `Start Date`,
coalesce(B.`BINOUT_DUE_DATE`, '') AS `Est End`
FROM hardware_tracking_msa.HAST_Detail A
LEFT JOIN
(SELECT X.*,
Y.`BINOUT_DUE_DATE`,
Y.`LOT_LOCATION`
FROM skynet_msa.lots_to_hast_boards X
LEFT JOIN skynet_msa.labs_inventory Y ON X.`lotid` = Y.`LOTID`) B ON A.`Serial_Number` = B.`board_sn`
WHERE `LOTID` IS NOT NULL);
I would like to know what makes it take longer than 30 seconds to run and how to improve the query. Any help is appreciated thanks!
Output for hardware_tracking_msa.HAST_Detail:
Index, Board_Number, SIG_Number, Board_ID, Serial_Number, Design_ID, Package, Sockets, Socket_Number, Status, Notes, Deleted_By, Inserted_Date, Inserted_By, Updated_Date, Updated_By, Deleted_Date
'1', '2759', '594-11269', '2759-001', '605637/001', 'J4Q2', 'WFBGA, PIN COUNT: 168/529,PACKAGE SIZE: 12x12', '40', '530-10670 SINGLE BIAS (ESPEC)CANNOT USE FOR J80C/J4Q2', '', '', '', '2022-05-17 14:00:00', 'NWANGA', '2022-05-18 10:15:41', 'tmingyao', '2022-05-17 14:57:33'
'2', '2759', '594-11269', '2759-002', '605637/008', 'J4Q2', 'WFBGA, PIN COUNT: 168/529,PACKAGE SIZE: 12x12', '40', '530-10670 SINGLE BIAS (ESPEC)CANNOT USE FOR J80C/J4Q2', NULL, '', '', '2022-05-17 14:00:00', 'NWANGA', '2022-05-17 14:57:33', '', '2022-05-17 14:57:33'
'3', '2759', '594-11269', '2759-003', '608061/001', 'J4Q2', 'WFBGA, PIN COUNT: 168/529,PACKAGE SIZE: 12x12', '40', '530-10670 SINGLE BIAS (ESPEC)CANNOT USE FOR J80C/J4Q2', NULL, '', '', '2022-05-17 14:00:00', 'NWANGA', '2022-05-17 14:57:33', '', '2022-05-17 14:57:33'
Output for skynet_msa.lots_to_hast_boards:
\begin{table}[]
\begin{tabular}{lll}
lotid, & board\_sn, & created\_date \\
'CVZ2JL2.11', & '1790247/003', & '2022-07-20 '14:26:04 \\
'CV4YJL2.11', & '1317876/002', & '2022-07-20 14:26:04 \\
'CVRMHL2.11', & '1790241/014', & '2022-07-20 14:26:04
\end{tabular}
\end{table}
Output for skynet_msa.labs_inventory:
LOTID, LOCATION, ENV_TEST_INTERVAL, EST_DURATION_TIME, ENV_STRESS_VOLTAGE, ENV_STRESS_VOLT_2, ENV_STRESS_VOLT_3, PRODUCT_FAMILY, PRODUCT_TECHNOLOGY, DESIGN_ID, QA_WORK_REQUEST_NO, QA_PROCESS_TYPE, QA_PROCESS_NAME, QA_BURN_EXPERIMENT, QA_CONTACT, QA_PROCESS_LOT_NO, FABRICATION_FACILITY, ASSEMBLY_FACILITY, ELEC_TEST_FLOW, CONFIGURATION_WIDTH, NUMBER_OF_DIE_IN_PKG, CURRENT_QTY, LOT_LOCATION, LEAD_COUNT, PACKAGE_TYPE, PACKAGE_LENGTH, PACKAGE_WIDTH, PACKAGE_HEIGHT, SOAK_LEVEL, BAKE_TEMPERATURE, DRB_TEMPERATURE, ACTUAL_CURE_TIME, REFLOW_PROFILE, PINOUT_VERSION, DISPATCH_DUE_DATE, BINOUT_DUE_DATE, ROW_CREATED, ROW_MODIFIED, LOCATION_DATE, LOCATION_WW, MODULE_LOT, BURN_LOT, MONITOR_IGNORE, TICKER, PRIORITY, ASM_LOT_NUMBER, MARK_FORMAT, LOCATION_TAT, RPM_WW, QA_EVENT_ID, TC_WEIGHT, AUTOMOTIVE_LOT, CUSTOMER_OPTION, PKG_RECEIVE_DATE, CUSTOMER_GROUP, SAMPLE_PULLED_DATE, QA_SPECIAL_FLOW, QA_BLOCKS, PROBE_CUSTOM_TESTED, QA_PROGRAM_REV, NAND_FLOW_TYPE, NUM_FLASH_CE_PINS, RETICLE_WAVE_ID, MAJOR_PROBE_PROG_REV, MAJOR_TEST_PROG_REV, CYCLING_TYPE, QA_TARGET_CYCLE, LAST_TEST_INTERVAL, CYCLING_TEMPERATURE, ENV_STRESS_DURATION, FIRST_TEST_INTERVAL, DRB_TARGET_INTERVAL, LTDR_TEMPERATURE, RD_STRESS_TYPE
'1623941.001', 'TEMP CYCLE K INV', '25', '12.50', '0.000', '0.000', '0.000', 'MCP', 'ALL IN ONE MCP', 'UM181', '', 'PRODUCTION SCREEN', 'TEMP CYCLE K', '', '', '', 'MIXED', 'ASSEMBLY-MSA', '', '', '8', '2439', 'S01-AR-ASRSIN', '254/432', 'TFBGA', '13.000', '11.500', '1.100', '', '0', '0', '0', '', 'JEDEC', '1970-01-01 00:00:00', NULL, '2022-06-05 18:35:12', '2022-06-06 00:00:16', '2022-06-05 18:35:00', '202223', '0', '0', '0', '0', '4', '1623941.001', '', '1.57', '', 'QA 13', '0', '', '', '1970-01-01 00:00:00', '', '1970-01-01 00:00:00', '', '', 'MOBILE C', '', '', '4', '', '', '', '', '', '', '', '25', '', '', '', ''
'BC4WSXZ.31', 'THERMAL WARPAGE', '0', '0.00', '0.000', '0.000', '0.000', 'MCP', 'MASSFLASH/LPDDR4', 'J86L', '', 'PRODUCTION SCREEN', 'THERMAL WARPAGE', '', '', '', 'MIXED', 'PTI P3', '', '', '2', '26', '', '194/1026', 'UFBGA', '9.000', '12.500', '0.545', '', '0', '0', '0', '', 'AVALON', '1970-01-01 00:00:00', NULL, '2022-07-19 11:00:17', '2022-07-20 13:30:15', '2022-07-19 11:26:45', '202229', '0', '0', '0', '0', '4', 'PT22900.25', 'AVALON', '0.28', '', 'QA 32', '0', '', '', '1970-01-01 00:00:00', '', '2022-07-19 10:58:00', '', '', '', '', '', '1', '', '', '29', '', '', '', '', '', '', '', '', ''
'BC6VVLZ.31', 'TEMP CYCLE K INV', '25', '12.50', '0.000', '0.000', '0.000', 'MCP', 'MASSFLASH/CONTROLLER', 'J39E', '', 'PRODUCTION SCREEN', 'TEMP CYCLE K', '', '', '', 'FAB 10', 'ASSEMBLY-MSA', '', 'X4-X8', '4', '320', 'S01-REL-LAB-IN', '153/196', 'VFBGA', '13.000', '11.500', '1.000', '', '0', '0', '0', '', 'JEDEC', '1970-01-01 00:00:00', NULL, '2022-07-10 14:35:16', '2022-07-11 07:15:19', '2022-07-10 14:31:49', '202228', '0', '0', '0', '0', '4', 'BF3HFCQ.5X', '', '419.25', '', 'QA 45', '0', 'YES', 'AUTOMOTIVE', '1970-01-01 00:00:00', '', '1970-01-01 00:00:00', '', '', 'NAND AUTO', '', '', '4', 'WAVE007', '22', '', '', '', '', '', '25', '', '', '', ''
show create table hardware_tracking_msa.HAST_Detail:
CREATE TABLE `HAST_Detail` (
`Index` int NOT NULL AUTO_INCREMENT,
`Board_Number` varchar(250) DEFAULT \'\',
`SIG_Number` varchar(250) DEFAULT \'\',
`Board_ID` varchar(250) DEFAULT \'\',
`Serial_Number` varchar(250) DEFAULT \'\',
`Design_ID` varchar(150) DEFAULT \'\',
`Package` varchar(250) DEFAULT \'\',
`Sockets` int DEFAULT \'0\',
`Socket_Number` varchar(250) DEFAULT \'\',
`Status` varchar(45) DEFAULT NULL,
`Notes` varchar(1000) DEFAULT \'\',
`Deleted_By` varchar(20) DEFAULT \'\',
`Inserted_Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Inserted_By` varchar(20) NOT NULL DEFAULT \'\',
`Updated_Date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`Updated_By` varchar(20) DEFAULT \'\',
`Deleted_Date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`Index`)
) ENGINE=InnoDB AUTO_INCREMENT=1459 DEFAULT CHARSET=utf8'
show create table skynet_msa.lots_to_hast_boards:
CREATE TABLE `lots_to_hast_boards` (
`lotid` varchar(45) NOT NULL DEFAULT \'\',
`board_sn` varchar(45) NOT NULL DEFAULT \'\',
`created_date` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`lotid`,`board_sn`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1'
show create table skynet_msa.labs_inventory:
CREATE TABLE `labs_inventory` (
`LOTID` varchar(12) NOT NULL,
`LOCATION` varchar(48) NOT NULL,
`ENV_TEST_INTERVAL` int DEFAULT \'0\',
`EST_DURATION_TIME` decimal(8,2) DEFAULT \'0.00\',
`ENV_STRESS_VOLTAGE` decimal(6,3) DEFAULT NULL,
`ENV_STRESS_VOLT_2` decimal(6,3) DEFAULT NULL,
`ENV_STRESS_VOLT_3` decimal(6,3) DEFAULT NULL,
`PRODUCT_FAMILY` varchar(45) DEFAULT NULL,
`PRODUCT_TECHNOLOGY` varchar(45) DEFAULT NULL,
`DESIGN_ID` varchar(6) DEFAULT NULL,
`QA_WORK_REQUEST_NO` varchar(100) DEFAULT NULL,
`QA_PROCESS_TYPE` varchar(45) DEFAULT NULL,
`QA_PROCESS_NAME` varchar(64) DEFAULT NULL,
`QA_BURN_EXPERIMENT` varchar(45) DEFAULT NULL,
`QA_CONTACT` varchar(45) DEFAULT NULL,
`QA_PROCESS_LOT_NO` varchar(12) DEFAULT NULL,
`FABRICATION_FACILITY` varchar(45) DEFAULT NULL,
`ASSEMBLY_FACILITY` varchar(45) DEFAULT NULL,
`ELEC_TEST_FLOW` varchar(45) DEFAULT NULL,
`CONFIGURATION_WIDTH` varchar(8) DEFAULT NULL,
`NUMBER_OF_DIE_IN_PKG` int DEFAULT NULL,
`CURRENT_QTY` int DEFAULT NULL,
`LOT_LOCATION` varchar(45) DEFAULT NULL,
`LEAD_COUNT` varchar(45) DEFAULT \'\',
`PACKAGE_TYPE` varchar(45) DEFAULT \'\',
`PACKAGE_LENGTH` decimal(6,3) DEFAULT \'0.000\',
`PACKAGE_WIDTH` decimal(6,3) DEFAULT \'0.000\',
`PACKAGE_HEIGHT` decimal(6,3) DEFAULT \'0.000\',
`SOAK_LEVEL` varchar(45) DEFAULT NULL,
`BAKE_TEMPERATURE` varchar(30) DEFAULT NULL,
`DRB_TEMPERATURE` varchar(30) DEFAULT NULL,
`ACTUAL_CURE_TIME` int DEFAULT NULL,
`REFLOW_PROFILE` varchar(45) DEFAULT NULL,
`PINOUT_VERSION` varchar(45) DEFAULT NULL,
`DISPATCH_DUE_DATE` datetime DEFAULT NULL,
`BINOUT_DUE_DATE` datetime DEFAULT NULL,
`ROW_CREATED` datetime NOT NULL,
`ROW_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`LOCATION_DATE` timestamp NOT NULL DEFAULT \'1970-01-01 12:00:00\',
`LOCATION_WW` varchar(10) DEFAULT NULL,
`MODULE_LOT` int NOT NULL DEFAULT \'0\',
`BURN_LOT` int DEFAULT \'0\',
`MONITOR_IGNORE` int NOT NULL DEFAULT \'0\',
`TICKER` int NOT NULL DEFAULT \'0\',
`PRIORITY` varchar(4) DEFAULT NULL,
`ASM_LOT_NUMBER` varchar(45) DEFAULT NULL,
`MARK_FORMAT` varchar(45) DEFAULT NULL,
`LOCATION_TAT` double DEFAULT \'0\',
`RPM_WW` varchar(10) DEFAULT NULL,
`QA_EVENT_ID` varchar(15) DEFAULT NULL,
`TC_WEIGHT` double DEFAULT \'0\',
`AUTOMOTIVE_LOT` varchar(45) DEFAULT NULL,
`CUSTOMER_OPTION` varchar(45) DEFAULT NULL,
`PKG_RECEIVE_DATE` datetime DEFAULT NULL,
`CUSTOMER_GROUP` varchar(45) DEFAULT NULL,
`SAMPLE_PULLED_DATE` datetime DEFAULT NULL,
`QA_SPECIAL_FLOW` varchar(45) DEFAULT NULL,
`QA_BLOCKS` varchar(45) DEFAULT NULL,
`PROBE_CUSTOM_TESTED` varchar(45) DEFAULT NULL,
`QA_PROGRAM_REV` varchar(45) DEFAULT NULL,
`NAND_FLOW_TYPE` varchar(45) DEFAULT NULL,
`NUM_FLASH_CE_PINS` varchar(45) DEFAULT NULL,
`RETICLE_WAVE_ID` varchar(45) DEFAULT NULL,
`MAJOR_PROBE_PROG_REV` varchar(45) DEFAULT NULL,
`MAJOR_TEST_PROG_REV` varchar(45) DEFAULT NULL,
`CYCLING_TYPE` varchar(45) DEFAULT NULL,
`QA_TARGET_CYCLE` varchar(45) DEFAULT NULL,
`LAST_TEST_INTERVAL` varchar(45) DEFAULT NULL,
`CYCLING_TEMPERATURE` varchar(45) DEFAULT NULL,
`ENV_STRESS_DURATION` varchar(45) DEFAULT NULL,
`FIRST_TEST_INTERVAL` varchar(45) DEFAULT NULL,
`DRB_TARGET_INTERVAL` varchar(45) DEFAULT NULL,
`LTDR_TEMPERATURE` varchar(45) DEFAULT NULL,
`RD_STRESS_TYPE` varchar(45) DEFAULT NULL,
PRIMARY KEY (`LOTID`),
KEY `design_id` (`DESIGN_ID`),
KEY `lot_location` (`LOT_LOCATION`),
KEY `burn` (`DESIGN_ID`,`QA_BURN_EXPERIMENT`),
KEY `locations` (`LOT_LOCATION`,`LOCATION`),
KEY `all_index` (`LOCATION`,`LOT_LOCATION`,`DISPATCH_DUE_DATE`,`PRODUCT_FAMILY`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
COMMENT=\'table to store MAM data for msa labs skynet\''
EXPLAIN QUERY:
id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'X', NULL, 'ALL', 'PRIMARY', NULL, NULL, NULL, '55', '90.00', 'Using where'
'1', 'SIMPLE', 'Y', NULL, 'eq_ref', 'PRIMARY', 'PRIMARY', '14', 'skynet_msa.X.lotid', '1', '100.00', 'Using where'
'1', 'SIMPLE', 'A', NULL, 'ALL', NULL, NULL, NULL, NULL, '1458', '10.00', 'Using where; Using join buffer (hash join)'
Change from MyISAM to InnoDB. (It may not matter for this query.)
Tentative index to add:
A: INDEX(Serial_Number, status)
LEFT is not needed:
LEFT JOIN ( ... ) B ON ... WHERE b.id IS NOT NULL
-->
JOIN ( ... ) B ON ...
At that point, it may be reasonable to get rid of the nested LEFT JOIN, and simply have a single level A, X, Y joined together.
The EXPLAIN shows that at least some of those simplifications were automatically figured out by the Optimizer.
A.Serial_Number = B.`board_sn
I see "utf8" and "latin1". If any query JOINs on a VARCHAR between different Character Sets, (ore Collations), an otherwise-suitable index will not be used. If that is a problem, I suggest you use ALTER .. CONVERT TO .. to change latin1 to utf8.
I see columns called "DURATION" and "INTERVAL" being declared VARCHAR. This can cause trouble if you ever do numeric operations on such columns. (I understand things like "BOARD_SN" are not really numbers.)

View returning 0 rows but same query returns 63 rows

I am having strange results in mysql. I have a view which when executed returns 0 rows but taking the query out of the VIEW and executing it as it is returns 63 rows.
This was working properly but ever since I have migrated the code to AWS RDS I am having this error. I am not able to make any sense why this is happening?
I don't even get any error just the 0 rows being returned.
From here on I am just writing random words because I am not able to post the question as the line of code is more. THis is really annnoying ahh darn I made a typo it must be annoying and not annnoying. My bad I hope you all arent mad at this, I am at my wits end how much more should I type?
I am unable to create a sqlfiddle as the request is too large, I am creating a fiddle like dump if you guys want to recreate it on on your end.
I have also discovered that removing the left join from the VIEW returns results.
The fiddle like dump below returns 3 rows when running the select but the VIEW returns 0 rows
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`user_type` enum('admin','landlord','renter') NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email_id` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`company_name` varchar(255) NOT NULL,
`street_address` varchar(255) NOT NULL,
`city` varchar(100) NOT NULL,
`state` varchar(100) NOT NULL,
`zip` varchar(100) NOT NULL,
`phone_no` varchar(50) NOT NULL,
`bank_name` varchar(100) NOT NULL,
`billing_address` varchar(255) NOT NULL,
`name_on_card` varchar(255) NOT NULL,
`bank_account_number` varchar(100) NOT NULL,
`bank_routing_no` varchar(100) NOT NULL,
`has_payzang_account` int(11) NOT NULL DEFAULT '0',
`payzang_api` varchar(255) DEFAULT '',
`payzang_gateway_url` varchar(255) NOT NULL,
`pending_amount` decimal(18,2) DEFAULT NULL COMMENT 'pending key bank(rent deduct) amount for landlord',
`is_active` int(11) NOT NULL COMMENT '0-inactive/1-active',
`is_assigned` int(11) NOT NULL DEFAULT '0' COMMENT 'Is this user assigned to any property',
`assigned_to` int(11) NOT NULL COMMENT 'assigned to which landlord id',
`is_set_up_new_password` enum('0','1') NOT NULL DEFAULT '0' COMMENT 'When admin/landlord adds renter or admin adds landlord an email with id+password is sent to the user. The first time they sign in, it should prompt them to change password page. So this field indicating whether user set up their own password',
`created_at` datetime NOT NULL,
`modified_at` datetime NOT NULL,
`created_by` int(11) NOT NULL,
`modified_by` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `users` (`id`, `user_type`, `first_name`, `last_name`, `email_id`, `password`, `company_name`, `street_address`, `city`, `state`, `zip`, `phone_no`, `bank_name`, `billing_address`, `name_on_card`, `bank_account_number`, `bank_routing_no`, `has_payzang_account`, `payzang_api`, `payzang_gateway_url`, `pending_amount`, `is_active`, `is_assigned`, `assigned_to`, `is_set_up_new_password`, `created_at`, `modified_at`, `created_by`, `modified_by`, `is_deleted`) VALUES
(1, 'admin', 'Super', 'Admin', 'email#email.com', '$2y$10$NwcR0ObYeUM.OfjgMOaajeH6bjjuMTpU2GnF0h623SER37AFk8K9i', 'UIGJ', 'DJ Road', 'Kolkatr', '20', '522236', '(987) 963-9658', '', '', '', '', '', 1, 'xxxxxxxxxxxxxxxxxxxxx', 'https://payzang.transactiongateway.com/api/v2/three-step', '0.00', 1, 0, 0, '1', '2017-06-02 13:56:34', '2017-06-02 13:56:34', 0, 0, 0),
(2, 'landlord', 'Denise', 'Supplee', 'email1#email.com', '$2y$10$PATxnED1/lqr1t7epLJiwu0uVztuXJB97q/XQv7xLc/iCv/m4NK2G', '', '', '', '', '', '2156755615', '', '', '', '', '', 1, 'xxxxxxxxxxxxxxxxxxxxx', 'https://payzang.transactiongateway.com/api/v2/three-step', '230.77', 1, 0, 0, '0', '2017-09-06 16:31:23', '2017-09-10 05:48:45', 0, 1, 0),
(3, 'renter', 'Amanda', 'Scott', 'email2#email.com', '$2y$10$oBU3tbcVT63Asw6CDLCGB.SNAvSpJaOcLBx4NqodFNMwvlSRLc.tO', '', '', '', '', '', '(215) 672-3778', '', '', '', '', '', 0, '', '', NULL, 0, 0, 2, '1', '2017-09-06 17:54:02', '2017-09-06 17:54:02', 2, 0, 1),
(4, 'renter', 'Megan', 'Ridgell', 'email3#email.com', '$2y$10$mPR7U/ri/rpW2n5f6X4mV.6jCycvLTJ/dvttR8seMFSGgRR/tQh1.', '', '', '', '', '', '2154852222', '', '', '', '', '', 0, '', '', NULL, 0, 0, 11, '1', '2017-09-06 18:30:01', '2017-09-12 06:22:23', 0, 2, 1),
(5, 'landlord', 'Brian', 'Davis', 'email4#email.com', '$2y$10$NwcR0ObYeUM.OfjgMOaajeH6bjjuMTpU2GnF0h623SER37AFk8K9i', '', 'PO Box 123', 'Baltimore', '21', '21231', '4104999026', '', '', '', '', '', 0, '', '', '0.00', 1, 0, 0, '0', '2017-09-07 05:19:46', '2017-09-07 05:19:46', 0, 0, 0),
(6, 'renter', 'Greg', 'Davis', 'email5#email.com', '$2y$10$Bd6S4KMGec2NzqKcvsJ1huwmbfACu8oOn56JLFSVQFt6ANg0Vr.ZW', '', '', '', '', '', '4104999026', '', '', '', '', '', 0, '', '', NULL, 1, 0, 5, '1', '2017-09-07 05:30:58', '2017-09-17 04:22:30', 0, 2, 0),
(7, 'renter', 'Maddie', 'Evans', 'email6#email.com', '$2y$10$ry9DBBFJHRhCsV7wpU9s9OI9WQ8BWqCTdk0K9KyYw/VD10mb/yC3O', '', '', '', '', '', '4104999026', '', '', '', '', '', 0, '', '', NULL, 1, 0, 0, '0', '2017-09-07 06:07:10', '2017-09-17 04:14:48', 0, 5, 0),
(8, 'renter', 'Arijita', 'Dey', 'email7#email.com', '$2y$10$NwcR0ObYeUM.OfjgMOaajeH6bjjuMTpU2GnF0h623SER37AFk8K9i', '', '', '', '', '', '3433453535', '', '', '', '', '', 0, '', '', NULL, 0, 0, 2, '0', '2017-09-07 08:08:21', '2017-09-10 05:42:58', 0, 2, 1),
(9, 'renter', 'Arijita', 'Dey', 'email8#email.com', '$2y$10$NwcR0ObYeUM.OfjgMOaajeH6bjjuMTpU2GnF0h623SER37AFk8K9i', '', '', '', '', '', '(564) 564-5645', '', '', '', '', '', 0, '', '', NULL, 0, 0, 5, '0', '2017-09-07 11:05:33', '2017-09-07 11:05:33', 5, 0, 1),
(10, 'renter', 'Rick', 'Roy', 'email9#email.com', '$2y$10$PG/8SkAwOZsSkD.px9FGveFIbriavOTX6vdBWHHmdjQeKgbwr0/wu', '', '', '', '', '', '(533) 453-4534', '', '', '', '', '', 0, '', '', NULL, 0, 0, 5, '0', '2017-09-07 11:11:49', '2017-09-07 11:11:49', 5, 0, 1),
(11, 'landlord', 'Denise', 'Supplee', 'email0#email.com', '$2y$10$52H0QZMFK9ApK7JwaDV9qOlqyOxcyTH3QikQqXgAcLD.zrb.ggoQG', '', '', '', '', '', '2156755615', '', '', '', '', '', 1, 'xxxxxxxxxxxxxxxxxxxxx', 'https://payzang.transactiongateway.com/api/v2/three-step', '0.00', 1, 0, 0, '0', '2017-09-11 14:09:03', '2017-09-18 23:22:57', 0, 1, 0);
CREATE TABLE `lease_with_max_id` (
`id` int(11)
,`lease_id` int(11)
,`renter_id` int(11)
,`landlord_id` int(11)
,`property_id` int(11)
,`is_rent_deducted_form_filled_up` enum('0','1')
,`status` int(11)
,`is_deleted` enum('0','1')
,`is_lease_ended` enum('0','1')
);
CREATE TABLE `properties` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL COMMENT 'landlord''s id',
`property_name` varchar(255) NOT NULL,
`street_address` varchar(255) NOT NULL,
`street_address_2` varchar(255) DEFAULT NULL,
`city` varchar(100) NOT NULL,
`state` varchar(100) NOT NULL,
`zip` varchar(100) NOT NULL,
`rent_amount` decimal(18,2) DEFAULT '0.00',
`is_active` enum('0','1') NOT NULL,
`is_assigned` enum('0','1') NOT NULL DEFAULT '0' COMMENT 'Is assigned to some renter or not',
`created_at` datetime NOT NULL,
`modified_at` datetime NOT NULL,
`is_deleted` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `properties` (`id`, `user_id`, `property_name`, `street_address`, `street_address_2`, `city`, `state`, `zip`, `rent_amount`, `is_active`, `is_assigned`, `created_at`, `modified_at`, `is_deleted`) VALUES
(1, 2, 'Test Property', '330 Crooked Billet Rd', '', 'Hatboro', '39', '19040', '0.00', '0', '0', '2017-09-10 05:38:12', '2017-09-10 05:38:12', 0),
(2, 2, '', '515 Main St', 'Apt. 1809', 'Horsham', '39', '19044', '0.00', '1', '1', '2017-10-09 04:24:50', '2017-10-09 04:24:50', 1),
(3, 5, 'Test 1', '123 Brian\'s Test St.', 'Apt. 2', 'Baltimore', '21', '21231', '0.00', '1', '0', '2017-09-07 05:21:10', '2017-09-07 05:21:10', 1),
(4, 5, 'Test 1', '123 Brian\'s Test St.', 'Apt. 2', 'Baltimore', '21', '21231', '0.00', '1', '0', '2017-09-07 05:21:18', '2017-09-07 05:21:18', 1),
(5, 5, 'Test 1', '123 Brian\'s Test St.', 'Apt. 1503', 'Baltimore', '21', '21231', '0.00', '0', '0', '2017-09-11 13:49:11', '2017-09-11 13:49:11', 1),
(6, 5, 'Test 2', '123 Brian\'s Test St.', 'Apt. 1', 'Baltimore', '21', '21231', '0.00', '1', '1', '2017-10-03 04:31:18', '2017-10-03 04:31:18', 0);
CREATE TABLE `geo_states` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL DEFAULT '',
`abv` char(2) NOT NULL DEFAULT '',
`country` char(2) NOT NULL,
`is_state` char(1) DEFAULT NULL,
`is_lower48` char(1) DEFAULT NULL,
`slug` varchar(50) NOT NULL,
`latitude` float(9,6) DEFAULT NULL,
`longitude` float(9,6) DEFAULT NULL,
`population` bigint(20) UNSIGNED DEFAULT NULL,
`area` float(8,2) UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE VIEW `test` AS SELECT
`users`.`id` AS `id`,
`users`.`user_type` AS `user_type`,
`users`.`first_name` AS `first_name`,
`users`.`last_name` AS `last_name`,
CONCAT(
`users`.`first_name`,
' ',
`users`.`last_name`
) AS `landlord_name`,
`users`.`email_id` AS `email_id`,
`users`.`password` AS `password`,
`users`.`company_name` AS `company_name`,
`users`.`street_address` AS `street_address`,
`users`.`city` AS `city`,
`users`.`state` AS `state`,
`users`.`zip` AS `zip`,
`users`.`phone_no` AS `phone_no`,
`users`.`bank_name` AS `bank_name`,
`users`.`billing_address` AS `billing_address`,
`users`.`name_on_card` AS `name_on_card`,
`users`.`bank_account_number` AS `bank_account_number`,
`users`.`bank_routing_no` AS `bank_routing_no`,
`users`.`has_payzang_account` AS `has_payzang_account`,
(
CASE WHEN(`users`.`has_payzang_account` = 0) THEN 'No' WHEN(`users`.`has_payzang_account` = 1) THEN 'Yes'
END
) AS `has_payzang_account_custom`,
`users`.`payzang_api` AS `payzang_api`,
`users`.`payzang_gateway_url` AS `payzang_gateway_url`,
`users`.`pending_amount` AS `pending_amount`,
`users`.`is_active` AS `is_active`,
(
CASE WHEN(`users`.`is_active` = '0') THEN 'Inactive' WHEN(`users`.`is_active` = '1') THEN 'Active'
END
) AS `is_active_custom`,
`users`.`is_assigned` AS `is_assigned`,
`users`.`assigned_to` AS `assigned_to`,
`users`.`is_set_up_new_password` AS `is_set_up_new_password`,
`users`.`created_at` AS `created_at`,
`users`.`modified_at` AS `modified_at`,
`users`.`created_by` AS `created_by`,
`users`.`modified_by` AS `modified_by`,
`users`.`is_deleted` AS `is_deleted`,
`lease_with_max_id`.`id` AS `lease_with_max_id_id`,
`lease_with_max_id`.`lease_id` AS `lease_with_max_id_lease_id`,
`lease_with_max_id`.`renter_id` AS `lease_with_max_id_renter_id`,
`lease_with_max_id`.`landlord_id` AS `lease_with_max_id_landlord_id`,
`lease_with_max_id`.`property_id` AS `lease_with_max_id_property_id`,
`lease_with_max_id`.`is_rent_deducted_form_filled_up` AS `lease_with_max_id_is_rent_deducted_form_filled_up`,
`lease_with_max_id`.`status` AS `lease_with_max_id_status`,
`lease_with_max_id`.`is_deleted` AS `lease_with_max_id_is_deleted`,
`properties`.`id` AS `property_id`,
`properties`.`user_id` AS `property_user_id`,
`properties`.`property_name` AS `property_property_name`,
`properties`.`street_address` AS `property_street_address`,
`properties`.`street_address_2` AS `property_street_address_2`,
`properties`.`city` AS `property_city`,
`properties`.`state` AS `property_state`,
`properties`.`zip` AS `property_zip`,
`properties`.`rent_amount` AS `property_rent_amount`,
`properties`.`is_active` AS `property_is_active`,
`properties`.`is_assigned` AS `property_is_assigned`,
`properties`.`created_at` AS `property_created_at`,
`properties`.`modified_at` AS `property_modified_at`,
`properties`.`is_deleted` AS `property_is_deleted`,
`geo_states`.`name` AS `geo_states_name`
FROM
(
(
(
`users`
LEFT JOIN `lease_with_max_id` ON
(
(
`lease_with_max_id`.`renter_id` = `users`.`id`
)
)
)
LEFT JOIN `properties` ON
(
(
`properties`.`id` = `lease_with_max_id`.`property_id`
)
)
)
LEFT JOIN `geo_states` ON
(
(
`geo_states`.`id` = `properties`.`state`
)
)
)
WHERE
(
(`users`.`user_type` = 'landlord') AND(`users`.`is_deleted` = 0)
)
ORDER BY
`users`.`id`
DESC
;

Query was working in MYSQL but not MYSQLI

My query was working in MYSQL but not in MYSQLI.
I'm selecting students that have done the pre AND post test.
SELECT
studid as Username,
prepoints as 'Fitness Assessment Points Grade',
end AS 'End-of-Line Indicator'
FROM
fittest, points
WHERE
YEAR(submitted) = '2017'
AND semester = 'summer2'
GROUP BY studid
HAVING
(MAX(prepost = 'pre' ) + MAX(prepost = 'post')) = 2 AND COUNT(DISTINCT prepost) = 2
Any ideas what changes need to be made to get it working again?
Here is some sample data:
CREATE TABLE `fittest` ( `id` int(11) NOT NULL, `submitted`
datetime DEFAULT NULL, `studid` varchar(100) DEFAULT NULL,
`semester` varchar(50) DEFAULT NULL, `instructor` varchar(30)
DEFAULT NULL, `course` enum('PHED 1164') DEFAULT NULL, `section`
enum('5001','5003','5005','5007','5009','5011','5013','5015','5017','5019','5021','5023','5025','5027','5029','5031','5033','5035','5037','5039','5041','5043','5045','5047','5049','5051','5053','5055','5057','5059','5061','5063','5065','5067','5069')
DEFAULT NULL, `age` varchar(50) DEFAULT NULL, `gender`
enum('m','f') DEFAULT NULL, `ethnicity` enum('Hispanic','African
American','Asian','White-Non Hispanic','Other') DEFAULT NULL,
`height` char(4) DEFAULT NULL, `weight` int(3) DEFAULT NULL,
`flexibility` int(2) DEFAULT NULL, `crunches` int(3) DEFAULT NULL,
`pushups` int(3) DEFAULT NULL, `treadtimemin` int(2) DEFAULT NULL,
`treadtimesec` int(2) NOT NULL, `treadhr` int(3) DEFAULT NULL,
`prepost` enum('pre','post') NOT NULL, `end` char(1) NOT NULL
DEFAULT '#' ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `fittest` (`id`, `submitted`, `studid`, `semester`,
`instructor`, `course`, `section`, `age`, `gender`, `ethnicity`,
`height`, `weight`, `flexibility`, `crunches`, `pushups`,
`treadtimemin`, `treadtimesec`, `treadhr`, `prepost`, `end`) VALUES
(17, '2017-01-02 21:55:33', 'slacker', 'spring', 'Tim', 'PHED 1164',
'5001', '32', 'm', NULL, '69.5', 155, NULL, 29, 34, 22, 15, 76, 'pre',
'#'), (16, '2017-01-02 21:31:34', 'bfun', 'spring', 'Tim', 'PHED
1164', '5001', '32', 'm', NULL, '69.5', 122, NULL, 37, 36, 18, 14, 76,
'post', '#'), (15, '2017-01-02 21:31:09', 'bfun', 'spring', 'Tim',
'PHED 1164', '5001', '32', 'm', NULL, '69.5', 129, NULL, 21, 20, 23,
14, 76, 'pre', '#'),
I just figured out the issue isn't with the query. It was with the input. All the input had post for the prepost value so there were no results that were showing. Thanks for your help.

How to populate mysql database column to json values

I try to populate mysql database column values to json values of items without success.
Database structure:
CREATE TABLE IF NOT EXISTS `ejkb4_k2_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(11) NOT NULL,
`title` varchar(255) NOT NULL,
`alias` varchar(255) DEFAULT NULL,
`catid` int(11) NOT NULL,
`published` smallint(6) NOT NULL DEFAULT '0',
`introtext` mediumtext,
`fulltext` mediumtext,
`video` text,
`gallery` varchar(255) DEFAULT NULL,
`extra_fields` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`extra_fields_search` text NOT NULL,
`created` datetime NOT NULL,
`created_by` int(11) NOT NULL DEFAULT '0',
`created_by_alias` varchar(255) NOT NULL,
`checked_out` int(10) unsigned NOT NULL,
`checked_out_time` datetime NOT NULL,
`modified` datetime NOT NULL,
`modified_by` int(11) NOT NULL DEFAULT '0',
`publish_up` datetime NOT NULL,
`publish_down` datetime NOT NULL,
`trash` smallint(6) NOT NULL DEFAULT '0',
`access` int(11) NOT NULL DEFAULT '0',
`ordering` int(11) NOT NULL DEFAULT '0',
`featured` smallint(6) NOT NULL DEFAULT '0',
`featured_ordering` int(11) NOT NULL DEFAULT '0',
`image_caption` text NOT NULL,
`image_credits` varchar(255) NOT NULL,
`video_caption` text NOT NULL,
`video_credits` varchar(255) NOT NULL,
`hits` int(10) unsigned NOT NULL,
`params` text NOT NULL,
`metadesc` text NOT NULL,
`metadata` text NOT NULL,
`metakey` text NOT NULL,
`plugins` varchar(1024) NOT NULL DEFAULT 'k2storeitem_price=1',
`code_search` varchar(11) NOT NULL,
`language` char(7) NOT NULL,
PRIMARY KEY (`id`),
KEY `item` (`published`,`publish_up`,`publish_down`,`trash`,`access`),
KEY `catid` (`catid`),
KEY `created_by` (`created_by`),
KEY `ordering` (`ordering`),
KEY `featured` (`featured`),
KEY `featured_ordering` (`featured_ordering`),
KEY `hits` (`hits`),
KEY `language` (`language`),
FULLTEXT KEY `search` (`title`,`introtext`,`fulltext`,`extra_fields_search`,`image_caption`,`image_credits`,`video_caption`,`video_credits`,`metadesc`,`metakey`),
FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=992 ;
One item from this database table:
INSERT INTO `ejkb4_k2_items` (`id`, `code`, `title`, `alias`, `catid`, `published`, `introtext`, `fulltext`, `video`, `gallery`, `extra_fields`, `extra_fields_search`, `created`, `created_by`, `created_by_alias`, `checked_out`, `checked_out_time`, `modified`, `modified_by`, `publish_up`, `publish_down`, `trash`, `access`, `ordering`, `featured`, `featured_ordering`, `image_caption`, `image_credits`, `video_caption`, `video_credits`, `hits`, `params`, `metadesc`, `metadata`, `metakey`, `plugins`, `code_search`, `language`) VALUES
(992, '1234567', 'Спирателен вентил ХХХ', 'спирателен-вентил-ххх', 704, 1, '<ul>\r\n<li>материал</li>\r\n<li>още нещо</li>\r\n<li>друго...</li>\r\n<li>и още</li>\r\n</ul>', '', '<iframe width="560" height="315" src="https://www.youtube.com/embed/pMPinbC1VJ4" frameborder="0" allowfullscreen></iframe>', NULL, '[{"id":"1","value":"1\\""},{"id":"9","value":"22311"},{"id":"5","value":""},{"id":"6","value":""},{"id":"7","value":""},{"id":"8","value":""},{"id":"10","value":"\\u041f\\u0440\\u043e\\u0438\\u0437\\u0432\\u043e\\u0434\\u0438\\u0442\\u0435\\u043b \\u0425"}]', '1" 22311 Производител Х ', '2017-05-30 07:27:22', 50, '', 0, '0000-00-00 00:00:00', '2017-06-06 13:20:35', 50, '2017-05-30 07:27:22', '0000-00-00 00:00:00', 0, 1, 2, 0, 0, '', '', '', '', 14, '{"catItemTitle":"","catItemTitleLinked":"","catItemFeaturedNotice":"","catItemAuthor":"","catItemDateCreated":"","catItemRating":"","catItemImage":"","catItemIntroText":"","catItemExtraFields":"","catItemHits":"","catItemCategory":"","catItemTags":"","catItemAttachments":"","catItemAttachmentsCounter":"","catItemVideo":"","catItemVideoWidth":"","catItemVideoHeight":"","catItemAudioWidth":"","catItemAudioHeight":"","catItemVideoAutoPlay":"","catItemImageGallery":"","catItemImageGalleryWidth":"","catItemImageGalleryHeight":"","catItemDateModified":"","catItemReadMore":"","catItemCommentsAnchor":"","catItemK2Plugins":"","itemDateCreated":"","itemTitle":"","itemFeaturedNotice":"","itemAuthor":"","itemFontResizer":"","itemPrintButton":"","itemEmailButton":"","itemSocialButton":"","itemVideoAnchor":"","itemImageGalleryAnchor":"","itemCommentsAnchor":"","itemRating":"","itemImage":"","itemImgSize":"","itemImageMainCaption":"","itemImageMainCredits":"","itemIntroText":"","itemFullText":"","itemExtraFields":"","itemDateModified":"","itemHits":"","itemCategory":"","itemTags":"","itemAttachments":"","itemAttachmentsCounter":"","itemVideo":"","itemVideoWidth":"","itemVideoHeight":"","itemAudioWidth":"","itemAudioHeight":"","itemVideoAutoPlay":"","itemVideoCaption":"","itemVideoCredits":"","itemImageGallery":"","itemImageGalleryWidth":"","itemImageGalleryHeight":"","itemNavigation":"","itemComments":"","itemTwitterButton":"","itemFacebookButton":"","itemGooglePlusOneButton":"","itemAuthorBlock":"","itemAuthorImage":"","itemAuthorDescription":"","itemAuthorURL":"","itemAuthorEmail":"","itemAuthorLatest":"","itemAuthorLatestLimit":"","itemRelated":"","itemRelatedLimit":"","itemRelatedTitle":"","itemRelatedCategory":"","itemRelatedImageSize":"","itemRelatedIntrotext":"","itemRelatedFulltext":"","itemRelatedAuthor":"","itemRelatedMedia":"","itemRelatedImageGallery":"","itemK2Plugins":""}', '', 'robots=\nauthor=', '', '{"k2storeitem_enabled":"1","k2storeitem_sku":"","k2storeitem_price":"","k2storespecial_price":"","k2storeitem_tax":"0","k2storeitem_shipping":"0","k2storeitem_metrics":{"item_length":"0.00000000","item_width":"0.00000000","item_height":"0.00000000","item_length_class_id":"0","item_weight":"0.00000000","item_weight_class_id":"0"},"k2storeitem_cart_text":""}', '', '*');
All values from column code must be populated to column extra_fields - as value of id:9. For example {"id":"9","value":"22311"} must going to: {"id":"9","value":"1234567"} in all database items.

SQLBuddy: How to select database?

I have the following sql which I want to import with SQLBuddy.
However I get an error telling that no database selected.
Could anyone tell me what line I need to add please?
CREATE TABLE IF NOT EXISTS `jos_banner` (
`bid` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(11) NOT NULL DEFAULT '0',
`type` varchar(30) NOT NULL DEFAULT 'banner',
`name` varchar(255) NOT NULL DEFAULT '',
`alias` varchar(255) NOT NULL DEFAULT '',
`imptotal` int(11) NOT NULL DEFAULT '0',
`impmade` int(11) NOT NULL DEFAULT '0',
`...
...
...
PRIMARY KEY (`bid`),
KEY `viewbanner` (`showBanner`),
KEY `idx_banner_catid` (`catid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
--
-- Dumping data for table `jos_banner`
--
INSERT INTO `jos_banner` (`bid`, `cid`, `type`, `name`, `alias`, `imptotal`, `impmade`, `clicks`, `imageurl`, `clickurl`, `date`, `showBanner`, `checked_out`, `checked_out_time`, `editor`, `custombannercode`, `catid`, `description`, `sticky`, `ordering`, `publish_up`, `publish_down`, `tags`, `params`) VALUES
(1, 1, 'banner', 'OSM 1', 'osm-1', 0, 47, 0, 'osmbanner1.png', 'http://www.opensourcematters.org', '2004-07-07 15:31:29', 0, 0, '0000-00-00 00:00:00', '', '', 13, '', 0, 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', ''),
(2, 1, 'banner', 'OSM 2', 'osm-2', 0, 49, 0, 'osmbanner2.png', 'http://www.opensourcematters.org', '2004-07-07 15:31:29', 0, 0, '0000-00-00 00:00:00', '', '', 13, '', 0, 2, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', ''),
(3, 2, '', 'Joomla!', 'joomla', 0, 1363, 0, '', 'http://www.joomla.org', '2009-05-29 ...
...
...
In the SQLBuddy homepage you need to create a database first, name it as whatever you want and then from the left sidebar select your new created database, then from the top menu select Query, paste your sql and go on!
use databasename;
Like it says: select a database.
Say your database is called ShinsBlog, add this to the start of your code:
use ShinsBlog;