Multiple Updating not workiing on workbench - mysql

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?

Related

I am receiving duplicate column name, but based on values. When i change the value, there is no error

I am trying to use this query, but when there are the same value in different columns, I receive this error:
1060 - Duplicate column name "123"
For example here:
INSERT INTO chiro(in_out,chirocov,chirocov2,chiroded,chiromet,
chirocovp,chirooop,chirooopmet,chirooopcp,
chirovisit,chirouse,chiromax,chirodedapply,
chironum1,chironum2)
SELECT * FROM (SELECT 'in', 'no','individual','123','123','20',
'213','21243','10','14','5','2000','yes',
'0','1') AS tmp
WHERE NOT EXISTS (SELECT in_out,chirocov,chirocov2,
chiroded,chiromet,chirocovp,chirooop,
chirooopmet,chirooopcp, chirovisit,chirouse,
chiromax,chirodedapply,chironum1,chironum2
FROM chiro
WHERE chirocov='no'
AND chirocov2='individual'
AND chiroded='123'
AND chiromet='123'
AND chirocovp='20'
AND chirooop='213'
AND chirooopmet='213'
AND chirooopcp='10'
AND chirovisit='14'
AND chirouse='5'
AND chiromax='2000'
AND chirodedapply='yes'
AND chironum1='0'
AND chironum2='1')
LIMIT 1
But when i change the value, there won"t be any errors. like:
INSERT INTO chiro(in_out,chirocov,chirocov2,chiroded,
chiromet,chirocovp,chirooop,chirooopmet,
chirooopcp, chirovisit,chirouse,chiromax,
chirodedapply,chironum1,chironum2)
SELECT * FROM (SELECT 'in', 'no','individual','123','231','20',
'213','21243','10','14','5','2000',
'yes', '0','1') AS tmp
WHERE NOT EXISTS (SELECT in_out,chirocov,chirocov2,
chiroded,chiromet,chirocovp,chirooop,
chirooopmet,chirooopcp, chirovisit,chirouse,
chiromax,chirodedapply,chironum1,chironum2
FROM chiro
WHERE chirocov='no'
AND chirocov2='individual'
AND chiroded='123'
AND chiromet='123'
AND chirocovp='20'
AND chirooop='213'
AND chirooopmet='213'
AND chirooopcp='10'
AND chirovisit='14'
AND chirouse='5'
AND chiromax='2000'
AND chirodedapply='yes'
AND chironum1='0'
AND chironum2='1')
LIMIT 1
Could you help me and let me know what I am doing wrong?
Just remove the outer SELECT from:
SELECT * FROM (SELECT 'in', 'no','individual','123','123','20',
'213','21243','10','14','5','2000','yes',
'0','1') AS tmp
because it retrieves all the unnamed columns from the inner select with names that are their values, so there are 2 columns with the same name 123.
See a simplified demo of the problem.
Use this:
INSERT INTO chiro(
in_out, chirocov, chirocov2, chiroded, chiromet, chirocovp, chirooop, chirooopmet, chirooopcp,
chirovisit, chirouse, chiromax, chirodedapply, chironum1, chironum2
)
SELECT 'in', 'no', 'individual', '123', '123', '20', '213', '21243', '10', '14', '5', '2000', 'yes', '0', '1'
WHERE NOT EXISTS(
SELECT in_out, chirocov, chirocov2, chiroded, chiromet, chirocovp, chirooop, chirooopmet, chirooopcp,
chirovisit, chirouse, chiromax, chirodedapply, chironum1, chironum2
FROM chiro
WHERE chirocov='no' AND chirocov2='individual' AND chiroded='123' AND chiromet='123' AND chirocovp='20'
AND chirooop='213' AND chirooopmet='213' AND chirooopcp='10' AND chirovisit='14' AND chirouse='5'
AND chiromax='2000' AND chirodedapply='yes' AND chironum1='0' AND chironum2='1'
)
Also LIMIT 1 is not necessary.

MySQL - return values in order provided

In MySQL, I run a lot of SELECT statements with IN clauses. Sometimes I want to see the output table ordered by the order of values that I used in the IN clause, rather than alpha/numerical.
If I ran
SELECT id FROM x
WHERE id IN ('1', '3', '2', '0')
I would want output 1, 3, 2, 0, not 0, 1, 2, 3.
Is there a way to effect this?
Thanks!
With the following query you should get what you want:
SELECT id FROM x WHERE id IN ('1', '3', '2', '0') ORDER BY FIELD(id, '1', '3', '2', '0')
From the MySQL specification about FIELD():
Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found.
http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_field

Mysql escaping recount integers in REPLACE

I have a replace statement to replace numerical values in columns with text, the text may contain numbers, how to avoid re-replacing these numbers?
update
`obsmaintble`
set
`obsvteduration` = REPLACE(`obsvteduration`, '0', 'No C-Section'),
`obsvteduration` = REPLACE(`obsvteduration`, '1', 'LOS equal or more than \4 - Given up to discharge'),
`obsvteduration` = REPLACE(`obsvteduration`, '2', 'LOS equal or more than \4 - Given for < \4 days'),
`obsvteduration` = REPLACE(`obsvteduration`, '3', 'LOS less than \4 Given up to discharge'),
`obsvteduration` = REPLACE(`obsvteduration`, '4', 'Not given'),

How to do TAB spacing while inserting values in a table in phpmyadmin?

I want to tab space my data while inserting through sql in phpmyADMIN.
What should I do?
INSERT INTO `questions` (`id`, `question_name`, `answer1`, `answer2`, `answer3`, `answer4`, `answer5`, `answer6`, `answer`, `category_id`) VALUES(90,'C<br> java', '1', '2', '3', '4', '', '', '3', 2);
You can split the string up and place a tab in between: 'some' + CHAR(9) + 'string'. Note that 9 is the ASCII code for a horizontal tab. Perhaps easier is 'some\tstring', which is syntax common to many other languages.
See table 9.1 here: http://dev.mysql.com/doc/refman/5.0/en/string-literals.html

Error in Mysql query Insert or update

I am a little bit desesperate with this query, I can't find my fault:
INSERT INTO device (
Device_UUID,
Model,
Manufacturer,
Latitude,
Longitude,
Type,
Registration_Date,
Status,
API_Source)
values (
'WW',
'a',
'v',
'0.00',
'0.00',
'BUS',
'2014-01-01 12:11:11',
'1',
'R')
ON DUPLICATE KEY UPDATE
Model = "wwww",
Manufacturer = "bbbbb",
Registration_Date = "2014-01-01 12:11:11";
All fields are String, even latitud and longitude
Type is a keyword. Try to put Type inside some ".