Bluehost.com Web Hosting $6.95

how to swap two fields bertween two rows

This is a discussion on how to swap two fields bertween two rows within the MySQL Database forums, part of the Database Forums category; I have a table in which a field (ordine) is used for the orderer output of data. This is not ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-04-2007
incuso
 
Posts: n/a
Default how to swap two fields bertween two rows

I have a table in which a field (ordine) is used for the orderer
output of data.

This is not an index, since data are subdivided in different
categories and therefore the value is not unique for the whole table.

Sometimes I need to change the display order and I was used to use a
query like this one:

UPDATE globalmoneta as mon1,globalmoneta as mon2 SET
mon1.ordine="2",mon2.ordine="3" WHERE mon1.ordine="3" AND
mon2.ordine="2" AND mon1.parentid="W-CE3" AND mon2.parentid="W-CE3";

probably not very efficient, but acceptable since this operation is
not often performed.

Unfortunately, after a server upgrade this query is no more working. I
suspect this is due to a different mysql version but I can not check
it.

Any idea on how to obtain the same task with a different query?

Thanks,
Massimo

Reply With Quote
  #2 (permalink)  
Old 02-04-2007
Paul Lautman
 
Posts: n/a
Default Re: how to swap two fields bertween two rows

incuso wrote:
> I have a table in which a field (ordine) is used for the orderer
> output of data.
>
> This is not an index, since data are subdivided in different
> categories and therefore the value is not unique for the whole table.
>
> Sometimes I need to change the display order and I was used to use a
> query like this one:
>
> UPDATE globalmoneta as mon1,globalmoneta as mon2 SET
> mon1.ordine="2",mon2.ordine="3" WHERE mon1.ordine="3" AND
> mon2.ordine="2" AND mon1.parentid="W-CE3" AND mon2.parentid="W-CE3";
>
> probably not very efficient, but acceptable since this operation is
> not often performed.
>
> Unfortunately, after a server upgrade this query is no more working. I
> suspect this is due to a different mysql version but I can not check
> it.
>
> Any idea on how to obtain the same task with a different query?
>
> Thanks,
> Massimo


Try bracketing the tables this:
UPDATE (globalmoneta as mon1,globalmoneta as mon2) SET
mon1.ordine="2",mon2.ordine="3" WHERE mon1.ordine="3" AND
mon2.ordine="2" AND mon1.parentid="W-CE3" AND mon2.parentid="W-CE3";


Reply With Quote
  #3 (permalink)  
Old 02-04-2007
incuso
 
Posts: n/a
Default Re: how to swap two fields bertween two rows

On 4 Feb, 16:49, "Paul Lautman" <paul.laut...@btinternet.com> wrote:
> Try bracketing the tables this:
>


Same result...

The query doeas not give any error. Simply only mon1.ordine is
changed...

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0