I get an error when i execute this script:
create table orbeon_form_definition_attach (
created timestamp(6),
last_modified_time timestamp(6),
last_modified_by varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
app varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form_version int not null,
deleted char(1) COLLATE utf8_bin NOT NULL,
file_name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
file_content longblob
) engine = InnoDB;
The error is : Error Code: 1064. You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near (6), last_modified_time timestamp(6), last_modified_by varchar(255) at line 2 0.000 sec
any idea how to solve this??
datetime or timestamp does not have a length
create table orbeon_form_definition_attach
(
created datetime,
last_modified_time datetime,
last_modified_by varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
app varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form_version int not null,
deleted char(1) COLLATE utf8_bin NOT NULL,
file_name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
file_content longblob
) engine = InnoDB;
Related
Update / Answer
To fix this issue, I added the keyword BINARY to each side of the comparison operator. This generated the expected results. Also note that I set the variable to empty string. Setting this to NULL did not resolve the issue.
SET #previousstate = '';
SELECT
if(**BINARY** #previousstate != **BINARY** frm.fi_details_temp.PortfolioCode,
End Update / Answer
This is somewhat related to MYSQL Stored Procedure - Concat Row Value. That thread was based on Mysql 5.7.
The following statement worked under MySQL 5.7. I am in the process of trying to get it to work in MySql 8. I had to update the SET statement to 'SET #previousstate = NULL;' otherwise I get "Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '<>'". This error was way above my understanding. I am just a marketing guy working in a small firm. So that is why I set it to NULL.
With that said, after updating the SET statement the result set returns but the if() statement is not working like it did under 5.7. The very first row returned should have the first column of data marked with '*' at the beginning and end, and as the data in the column changes it should mark it too.
So it should look like this:
*brownfdn*
brownfdn
*brownfmi*
brownfmi
But I am getting this:
brownfdn
brownfdn
brownfmi
brownfmi
Do you have any thoughts about what I am doing wrong? I appreciate your help!! Getting to MySql 8 has been a struggle.
5.7
CREATE table fi_details_temp AS (
SELECT
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final
From
frm.fi_details
Where
frm.fi_details.manager = 'Bartz' And
frm.fi_details.PortfolioCode Like ('Crown%')
Group By
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final
Order By
frm.fi_details.PortfolioCode;
SET #previousstate = '';
SELECT
if(#previousstate != frm.fi_details_temp.PortfolioCode, concat('*',#previousstate:= frm.fi_details_temp.PortfolioCode,'*'), frm.fi_details_temp.PortfolioCode) as 'Portfolio Code',
frm.fi_details_temp.MaturityDate_Final as 'Maturity Date'
From frm.fi_details_temp;
DROP TABLE IF EXISTS fi_details_temp;
END
*** Create Statements - the above was a trimmed down version ***
CREATE TABLE `fi_details` (
`id` int NOT NULL AUTO_INCREMENT,
`RecordDate` datetime DEFAULT CURRENT_TIMESTAMP,
`PortfolioCode` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`manager` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`RunDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`RunDate_Final` date DEFAULT NULL,
`AsOfDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AsOfDate_Final` date DEFAULT NULL,
`Symbol` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Coupon` double DEFAULT NULL,
`MaturityDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`MaturityDate_Final` date DEFAULT NULL,
`ParValue` double DEFAULT NULL,
`MarketValue` double DEFAULT NULL,
`AdjustedUnitCost` double DEFAULT NULL,
`TotalAdjustedCost` double DEFAULT NULL,
`SPRating` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`MoodyRating` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`YieldCost` double DEFAULT NULL,
`YieldMarket` double DEFAULT NULL,
`YieldCall` double DEFAULT NULL,
`YieldPut` double DEFAULT NULL,
`YieldWorst` double DEFAULT NULL,
`WorstDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`WorstDate_Final` date DEFAULT NULL,
`CallDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`CallDate_Final` date DEFAULT NULL,
`CallPrice` double DEFAULT NULL,
`PutDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`PutDate_Final` date DEFAULT NULL,
`PutPrice` double DEFAULT NULL,
`FirstCouponDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`FirstCouponDate_Final` date DEFAULT NULL,
`LastCouponDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`LastCouponDate_Final` date DEFAULT NULL,
`Freq` int DEFAULT NULL,
`BondCalendarCode` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`SecTypeCode` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Security` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_fi_details_MaturityDate_Final` (`MaturityDate_Final`),
KEY `idx_fi_details_PortfolioCode` (`PortfolioCode`),
KEY `idx_fi_details_PortfolioCode_MaturityDate_Final` (`PortfolioCode`,`MaturityDate_Final`),
KEY `idx_fi_details_manager_MaturityDate_Final` (`manager`,`MaturityDate_Final`),
KEY `idx_fi_details_MaturityDate_Final_manager` (`MaturityDate_Final`,`manager`)
) ENGINE=InnoDB AUTO_INCREMENT=234850 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE DEFINER=`root`#`localhost` PROCEDURE `fi_details_Worst_Date_Hartz_Brown`()
BEGIN
DROP TABLE IF EXISTS fi_details_temp;
CREATE table fi_details_temp AS (
SELECT
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final,
frm.fi_details.YieldWorst,
frm.fi_details.WorstDate_Final,
frm.fi_details.YieldMarket,
frm.fi_details.Symbol,
frm.fi_details.Security,
frm.fi_details.Coupon,
frm.fi_details.ParValue,
frm.fi_details.MarketValue,
frm.fi_details.TotalAdjustedCost,
frm.fi_details.AdjustedUnitCost,
frm.fi_details.YieldCost,
frm.fi_details.YieldCall,
frm.fi_details.YieldPut,
frm.fi_details.CallDate_Final
From
frm.fi_details
Where
frm.fi_details.manager = 'Hartz' And
frm.fi_details.PortfolioCode Like ('Brown%')
Group By
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final,
frm.fi_details.YieldWorst,
frm.fi_details.WorstDate_Final,
frm.fi_details.YieldMarket,
frm.fi_details.Symbol,
frm.fi_details.Security,
frm.fi_details.Coupon,
frm.fi_details.ParValue,
frm.fi_details.MarketValue,
frm.fi_details.TotalAdjustedCost,
frm.fi_details.AdjustedUnitCost,
frm.fi_details.YieldCost,
frm.fi_details.YieldCall,
frm.fi_details.YieldPut,
frm.fi_details.CallDate_Final
Order By
frm.fi_details.PortfolioCode,
frm.fi_details.WorstDate_Final );
SET #previousstate = NULL;
SELECT
if(#previousstate != frm.fi_details_temp.PortfolioCode, concat('*',#previousstate:= frm.fi_details_temp.PortfolioCode,'*'), frm.fi_details_temp.PortfolioCode) as 'Portfolio Code',
frm.fi_details_temp.MaturityDate_Final as 'Maturity Date',
frm.fi_details_temp.YieldWorst as 'Worst Yield',
frm.fi_details_temp.WorstDate_Final as 'Worst Date',
frm.fi_details_temp.YieldMarket as 'Yield to Market',
frm.fi_details_temp.Symbol,
frm.fi_details_temp.Security as 'Description',
frm.fi_details_temp.Coupon,
frm.fi_details_temp.ParValue as 'Par Value',
frm.fi_details_temp.MarketValue as 'Market Value xAI',
frm.fi_details_temp.TotalAdjustedCost as 'Adjusted Cost',
frm.fi_details_temp.AdjustedUnitCost as 'Unit Adjusted Cost',
frm.fi_details_temp.YieldCost as 'Yield to Cost',
frm.fi_details_temp.YieldCall as 'Yield to Call',
frm.fi_details_temp.YieldPut as 'Yield to Put',
frm.fi_details_temp.CallDate_Final as 'Next Call Date'
From frm.fi_details_temp;
DROP TABLE IF EXISTS fi_details_temp;
END
This create statement is failing, and I can't see the reason. MySQL reports:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci, objObjectType VARCHAR(100) ' at line 3*
CREATE TABLE `my_object_attribute_map` (
`objID` INT(10) UNSIGNED auto_increment NOT NULL primary key,
`objForeignKey` VARCHAR(100) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`objObjectType` VARCHAR(100) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`objTypeName` VARCHAR(100) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`objLabel` VARCHAR(100) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`objValue` VARCHAR(100) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`objDateCreated` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`objCreatorID` CHAR(32) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
);
The not null constraint goes after the character set and collation:
CREATE TABLE `my_object_attribute_map` (
`objID` INT(10) UNSIGNED auto_increment NOT NULL primary key,
`objForeignKey` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`objObjectType` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
...
);
The syntax of column definitions has some warts; see https://dev.mysql.com/doc/refman/8.0/en/create-table.html and https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html.
Basically, the CHARACTER SET is part of the data type, and must come before the NOT NULL, which is an extra attribute that applies to any type. COLLATE I believe in principle is also part of the data type, and should also come before NOT NULL, but if you do specify it afterwards it still works (or is ignored, for non-string types), presumably for backwards compatibility.
Since the collation set also determines the character set, you could just leave character set out and specify COLLATE wherever you want.
I have google the problem I guess I am not the expert in sql thats why I cant seem to solve it.
I am exporting database from dedicated server and trying to import into google cloud instance apache / sql
I get error like below even I tried all answers in stackoverflow
Error
SQL query:
CREATE TABLE `islemler` (
`islemID` int(11) NOT NULL,
`islemKullaniciID` int(11) NOT NULL,
`islemTarih` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`islemBitisTarihi` datetime DEFAULT NULL,
`islemDurum` varchar(500) COLLATE utf8_turkish_ci NOT NULL,
`islemNot` varchar(500) COLLATE utf8_turkish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci
MySQL said: Documentation
1067 - Invalid default value for 'islemTarih'
please see the screen shot from link
Old database
New Database error
I appreciate some help...
As additional
I manage to create all tables manual, as much as from my sql knowledge.
I run below commands
CREATE TABLE oradamis_vt.islemler ( islemID INT(11) NOT NULL , islemKullaniciID INT(11) NOT NULL , islemTarih DATETIME NOT NULL , islemBitisTarihi DATETIME NOT NULL , islemDurum VARCHAR(500) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , islemNot VARCHAR(500) CHARACTER SET utf32 COLLATE utf32_turkish_ci NOT NULL ) ENGINE = InnoDB;
CREATE TABLE oradamis_vt.kullanicilar ( kullaniciID INT(11) NOT NULL , username VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , password VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciAdi VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciPozisyon VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciSkype VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciMail VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciTelefon VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciYetki VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL ) ENGINE = InnoDB;
CREATE TABLE oradamis_vt.version ( versionNumber INT(11) NOT NULL , sonIslemKullanici VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , sonIslem VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL ) ENGINE = InnoDB;
But at the end when I try to import from old SQL gives same error of startup.
quite frustrated :(
Try replacing with:
CREATE TABLE islemler ( islemID int(11) NOT NULL, islemKullaniciID int(11) NOT NULL, islemTarih timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, islemBitisTarihi datetime DEFAULT NULL, islemDurum varchar(500) COLLATE utf8_turkish_ci NOT NULL, islemNot varchar(500) COLLATE utf8_turkish_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci MySQL said: Documentation
I am new to MySQL and wants to create this table after reading tutorial I wrote this command but on MySQL Workbench it shows error for 4 line created_at attribute:
CREATE TABLE tweetMelbourne (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`geo_type` VARCHAR(8) CHARACTER SET utf8,
`created_at` DATETIME CHARACTER SET utf8 NOT NULL ,
`geo_coordinates_latitude` decimal(12,9) DEFAULT NULL,
`geo_coordinates_longitude` decimal(12,9) DEFAULT NULL,
`place_full_name` VARCHAR(35) CHARACTER SET utf8,
`place_country` VARCHAR(15) CHARACTER SET utf8,
`place_type` VARCHAR(18) CHARACTER SET utf8,
`place_bounding_box_type` VARCHAR(10) CHARACTER SET utf8,
`place_bounding_box_coordinates_NE_lat` decimal(12,9) DEFAULT NULL,
`place_bounding_box_coordinates_NE_long` decimal(12,9) DEFAULT NULL,
`place_bounding_box_coordinates_SW_lat` decimal(12,9) DEFAULT NULL,
`place_bounding_box_coordinates_SW_long` decimal(12,9) DEFAULT NULL,
`place_country_code` VARCHAR(5) CHARACTER SET utf8,
`place_name` VARCHAR(17) CHARACTER SET utf8,
`text` VARCHAR(140) CHARACTER SET utf8,
`user_id` INT,
`user_verified` VARCHAR(5) CHARACTER SET utf8,
`user_followers_count` INT,
`user_listed_count` INT,
`user_friends_count` INT,
`user_location` VARCHAR(30) CHARACTER SET utf8,
`user_following` VARCHAR(5) CHARACTER SET utf8,
`user_geo_enabled` VARCHAR(5) CHARACTER SET utf8,
`user_lang` VARCHAR(5) CHARACTER SET utf8,
PRIMARY KEY (id)
);
Error is :
Error Code: 1064. You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'CHARACTER SET utf8
have your tried with removing 'CHARACTER SET utf8'
Thank you guys it worked. I used DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci at the end. So, I think no need to define character set for datetime because its made up of numbers and doesn't include character.
I have two table the structure are given bellow, those table have lots of data but can't change the table stucture
Table "postsale"
CREATE TABLE IF NOT EXISTS `postsale` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season` varchar(25) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sale_no` int(5) NOT NULL,
`auction_date` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season_time` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lot_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`invoice_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`origin` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sub_tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`category` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`mark` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`grade` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`no_of_packages` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`gross_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`net_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_valuation` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lsp_sp` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`quantity` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auctioneer` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_price` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`buyer` text CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`area` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`broker_code` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`csv` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`session` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=29623 ;
and Table finalesale
CREATE TABLE IF NOT EXISTS `finalsale` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season` varchar(25) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sale_no` int(5) NOT NULL,
`auction_date` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season_time` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lot_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`invoice_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`origin` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sub_tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`category` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`mark` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`grade` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`no_of_packages` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`gross_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`net_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_valuation` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lsp_sp` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`quantity` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auctioneer` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_price` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`buyer` text CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`area` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`broker_code` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`csv` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`session` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=41365 ;
based on the above two table, the execution time of this query is huge so, I need to optimized the following query
UPDATE `finalsale`,`postsale`
SET
`finalsale`.`auction_price`=`postsale`.`auction_price`,
`finalsale`.`csv`=`postsale`.`csv`,
`finalsale`.`session`=`postsale`.`session`
WHERE `finalsale`.`lot_no`=`postsale`.`lot_no`
AND `finalsale`.`group_id`=`postsale`.`group_id`
AND `finalsale`.`group_id`='201217CLGuwahatiJT'
Please help
You will get a serious performance improvement from choosing the correct data types in your table definition.
There are several columns which appear to contain only numerical information, which is better stored in some int column.
Furthermore there are columns for some dates like auction_date that should be transformed to a date - datatype.
Also think about the length of your varchar columns. Most of the time you wont need the 255 characters there.
Have a close look at the Mysql Docu for datatypes.
If you have performance problems afterwards you may think about creating indexes on some columns. But I strongly recommend thinking about this just AFTER you reworked your table definitions!
Assuming it is not possible for you to improve on the schema (which as has been mentioned in the OP comments is rather... bloated), you probably would get a significant performance boost for this specific query by adding an index on lot_no and group_id on each of the tables.
Since you're using InnoDB, you might consider using a foreign key constraint (this also covers indexes), although it depends on the semantics & lifecycle of the tables, which I don't know about.
Add the following indexes:
Single column:
finalsale: (`group_id`)
Multi-column:
postsale: (`group_id, lot_no`)
These indexes allow MySQL to first limit the result set by applying the constant in the WHERE clause to the finalsale table, and then, with that minimal result set, perform a join to the postsale table, fully utilizing the index.