Skip to main content
Rollback to Revision 1 - Edit approval overridden by post owner or moderator
Source Link
Paul White
  • 90.3k
  • 30
  • 424
  • 663

How can I loopLoop a column value if rowRow exists using INSERT ON KEY DUPLICATE UPDATE?

In this table schemeTable Scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

Can'tI keep thinking but can't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE

How can I loop a column value if row exists using?

In this table scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

Can't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE

How can I Loop a column value if Row exists using INSERT ON KEY DUPLICATE UPDATE?

In this Table Scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

I keep thinking but can't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE

Correct grammar at title, content and changed tags for meaningful filtering
Source Link

How can I Looploop a column value if Rowrow exists using INSERT ON KEY DUPLICATE UPDATE?

In this Table Schemetable scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

I keep thinking but can'tCan't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE

How can I Loop a column value if Row exists using INSERT ON KEY DUPLICATE UPDATE?

In this Table Scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

I keep thinking but can't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE

How can I loop a column value if row exists using?

In this table scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

Can't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE

Source Link
Toleo
  • 318
  • 1
  • 4
  • 13

How can I Loop a column value if Row exists using INSERT ON KEY DUPLICATE UPDATE?

In this Table Scheme

[id  -  name  -  active]
[1   -  alex  -  0     ]

I have a UNIQUE KEY on name, active, What I'm trying to do is to INSERT a new Row

[2 - max - 1 ]

using INSERT INTO table (name, active) VALUES (max, 1) ON KEY DUPLICATE active = 0

That I want to loop at active column value,

If the row:[2-max-1] exists with active=1 to change active value to 0

And if exists with active=0 to change it to 1,

And if not exist to INSERT the row with active=1

I keep thinking but can't figure out a way to make this loop using only INSERT . . . ON KEY DUPLICATE UPDATE