Changing only one of 2 records which have the same values

code (country)
1 Germany
2 China
3 France
3 France
5 China[/code]

I have a table like the above.

if I use the SQL below, it will produce the result below.

SQL UPDATE myTable SET id=4 WHERE id=3 result 1 Germany 2 China 4 France 4 France 5 China

The would-be- SQL. which doesn’t work correctly will show what I want.

[code]Would-be-SQL
UPDATE myTable
SET id=4
WHERE only one of record among id=3

Target Result
1 Germany
2 China
3 France
4 France
5 China[/code]

How can I change only one of 2 records which have the same values?

Try this:

UPDATE myTable
SET id=4
WHERE id=3
LIMIT 1

Off topic:
You may also try Googling for duplicate records and making id unique to prevent further problems,

[quote=“John_Betong, post:2, topic:190544, full:true”]… and making id unique to prevent further problems,
[/quote]
joon has known about primary keys for years and years

i know because i taught him here in this forum

:slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.