Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Help with a SQL query
Old 06-06-2008, 02:10 PM Help with a SQL query
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Hi

I need help to create a smart SQL query for MySQL, to "which place" of two rows, without having to devide it into 4 queries. I'll recieve the ID of a row, and I want to decrease the field 'Order' of that row with 1, and at the same time, increase the Order of the row which currently have that Order number.
Ex.
Code:
ID  - Order - Other fields
-------------
106 - 4 - [other1]
134 - 5 - [other2]
194 - 6 - [other2]

which place... =>

ID  - Order
-------------
106 - 5 - [other1]
134 - 4 - [other2]
194 - 6 - [other2]
I should add that the field Order is Unique, so two of the rows can't have the same Order, evan if just temporarily (right?). I can't think of any smart way of doing this, only to first retrieve the Order of the given ID, then set it to something temporary (like -1), then increase the Order of the other row, and finaly set the correct Order of the row with the given ID.

Any help is appreciated
lizciz
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
 
Register now for full access!
Old 06-07-2008, 12:55 PM Re: Help with a SQL query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A stored procedure would be the only way to handle this scenario, and as you surmise would need the existing values setting to intermediate values before completing the update.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Help with a SQL query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26798 seconds with 12 queries