Here is the scenario:
UPDATED
Thanks to anakata for pointing out table locks and problems with overlapping sessions.
Start Transaction
Run a bunch of queries, these 2 in particular (private data removed):
START TRANSACTION
... various select statements...
INSERT INTO `leads` (`vertical_id`, `offer_id`, `campaign_id`, `affiliate_id`, `creative_id`, `is_test`, `ignoreme`, `qualified`, `usid`, `first_name`, `last_name`, `email`, `address`, `city`, `state`, `zip`, `phone`, `ip_address`, `referrer`, `duplicate_hash`, `address2`, `form_message`, `microtime`, `created`, `sub_id`, `score`, `imported`, `buyer_price`, `purchased_price`) VALUES ('45', '82', '151', '3', '0', 0, 0, 1, '0510', 'CharXX', 'MXX', 'XXXXX#yahoo.com', '451 XXX', 'Hagerstown', 'MD', '21740', '301-------', '405877318', 'X', 'e0534ea843c35d0f300ed4ff6e65b8db', '', 'redacted', '1368665153.6829', NOW(), '333', 0, 0, '0', '0')
INSERT INTO `fields_leads` (`lead_id`, `field_id`, `vertical_id`, `offer_id`, `campaign_id`, `value`) VALUES ('56575', '866', '45', '82', '151', 'CharXX')
COMMIT
Meanwhile other transactions are taking place. Post trasaction the insertID of 56575 is used as keys in other tables for various business related stuffs.
Problem is when you go to look for leads.id=56575 its gone! There are no DELETE FROM leads statements in the general.log. No rollback statements regarding this query either. I'm running MySQL client version: 5.0.77. Any insight would be super helpful, thanks!
Related
I have a database SQL table looking like this
[the database table]
So I'm trying to update this table simultaneously, such that one query updates multiple columns in multiple rows at once. The script looks like this
INSERT INTO teams
(id, team_name, matches_played, won, lost, points, goals_for, goals_against, goal_difference, last_match)
VALUES
('10', 'Manchester City', '3', '1', '', '3', '2', '0', '0', 'W'),
('5', 'Westham', '2', '', '1', '3', '0', '2', '-1', 'L')
ON DUPLICATE KEY UPDATE
team_name = VALUES(team_name),
matches_played = VALUES(matches_played),
won = VALUES(won),
lost = VALUES(lost),
points = VALUES (points),
goals_for = VALUES(goals_for),
goals_against = VALUE(goals_against),
goal_difference = VALUE(goal_difference),
last_match = VALUES(last_match);
My issue is. This code works perfectly on XAMPP MySQL server but not on workbench. What might the issue be?
Trying to create a new WordPress user directly through MySQL by running a query. I keep seeing an error message popup :
1292 - Incorrect datetime value: '0000-00-00 00:00:00' for column 'user_registered' at row 1
How can include what is missing?
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('adminuser2', MD5('adminuser2password'), 'adminfirstname adminlastname', 'adminuser2#mywebsite.com', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
Follow this syntax, it's the recommended way to insert data while you're using WordPress
$wpdb->insert( $table_name, array('column_name_1'=>'hello', 'other'=> 123), array( '%s', '%d' ) );
define a variable:
$blogtime = current_time( 'mysql' ); then add 'user_registered' column to your query
$wpdb->insert( 'wp_users' , array(
'user_login' => 'adminuser2',
'user_pass' => MD5('adminuser2password'),
'user_nicename'=> 'adminfirstname adminlastname',
'user_email'=> 'adminuser2#mywebsite.com',
'user_status'=> '0',
'user_registered'=> '$blogtime'
));
I am trying to create a list of employees showing their first name, hire date, and the city where they work. There are five employees listed but when I run my problem it only returns the first two from the location data entry.
Shown first is my employee data entered. When I run a select * statement for this table everything appears as it should. The problem comes when I try to run the second script shown, where it only shows the first two entries from the employee table.
first
INSERT INTO `salon`.`employee`
(`employee_id`,
`first_name`,
`last_name`,
`title`,
`hire_date`,
`termination_date`,
`email`,
`phone`,
`location_id`,
`manager_id`)
VALUES
(1,
'Jenny',
'Jensen',
'Owner',
'2013-06-15',
NULL,
'jensenj#salon.com',
2081112222,
1,
NULL),
(2,
'Haley',
'Lopez',
'Assistant Manager',
'2013-08-23',
NULL,
'lopezh#salon.com',
2083334444,
1,
1),
(3,
'Robert',
'Green',
'Associate',
'2014-01-03',
NULL,
'greenr#salon.com',
2085556666,
1,
2),
(4,
'Olive',
'Adams',
'Manager',
'2015-07-12',
NULL,
'adamso#salon.com',
2087778888,
2,
1),
(5,
'Julie',
'Davis',
'Associate',
'2015-10-20',
NULL,
'davisj#salon.com',
2089990000,
2,
4);
second script
SELECT employee.first_name, hire_date, location.city
FROM employee
JOIN location ON employee.employee_id = location.location_id
I try to insert my data to some table's of database I have tried the following:
INSERT INTO tbl_18189 (a,b,c,d,e) VALUES ( '1', '4 B', '%', '0', '0')
INSERT INTO tbl_3823 (a,b,c,d,e) VALUES ( '24000', '30 M', '34%', '885', '12.05')
INSERT INTO tbl_67126 (a,b,c,d,e) VALUES ( '3.99 M', '10 B', '10%', '530', '14.41')
INSERT INTO tbl_4247 (a,b,c,d,e) VALUES ( '1', '170 M', '%', '271', '22.77')
INSERT INTO tbl_23838 (a,b,c,d,e) VALUES ( '320000', '400 M', '7%', '407', '6.91')
but I got
Error creating table: 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 'INSERT INTO tbl_38232 ...
where is the problem in my code
UNION ALL joins SELECTs and you have none in your example. Remove them.
INSERT INTO tbl_18189 (a,b,c,d,e) VALUES ( '1', '4 B', '%', '0', '0');
INSERT INTO tbl_3823 (a,b,c,d,e) VALUES ( '24000', '30 M', '34%', '885', '12.05');
INSERT INTO tbl_67126 (a,b,c,d,e) VALUES ( '3.99 M', '10 B', '10%', '530', '14.41');
INSERT INTO tbl_4247 (a,b,c,d,e) VALUES ( '1', '170 M', '%', '271', '22.77');
INSERT INTO tbl_23838 (a,b,c,d,e) VALUES ( '320000', '400 M', '7%', '407', '6.91');
INSERT INTO `empleado` VALUES ('100', 'Alfonso', '1999-11-22', '100', '11');
INSERT INTO `empleado` VALUES ('101', 'Encarna', '2001-11-12', '100', '15');
INSERT INTO `empleado` VALUES ('102', 'Paco', '1999-10-16', '101', '12');
INSERT INTO `empleado` VALUES ('103', 'Juan Carlos', '1999-01-12', '101', '10');
That's my Date Type ,I need to select some codes that got into the company in the 3rd term of 1999
"select nombre,coddep,fecha_ingreso from
empleado where fecha_ingreso >1999;"
-that was my initial query, but it's wrong since it selects the name,cod and datetime >1999
This will fetch rows in the 3rd calendar quarter of 1999:
SELECT nombre, coddep, fecha_ingreso
FROM empleado
WHERE fecha_ingreso BETWEEN '1999-07-01' AND '1999-09-30'
If the field is DATETIME rather than DATE, change the second date to 1999-09-30 12:59:59
SELECT nombre, coddep, fecha_ingreso
FROM empleado
WHERE YEAR(fecha_ingreso) = 1999 AND QUARTER(fecha_ingreso) = 3
;