MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 31st, 2005, 02:27 PM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
Help Forumlate a Query...

Hello,

Say i have a table with only a url column.

Sample Data
----------------------------------------
http://whatever1
http://whatever2
http://whatever3
http://x.com/l/a.html
http://x.com/l/b.html
http://whatever4
http://x.com/l/c.html
http://x.com/l/d.html
http://whatever5
----------------------------------------

Now i wish to change all particular rows in the url col from x.com to x.com/new/[samepagename].htm.
For eg. http://x.com/l/a.html should change to http://x.com/new/a.htm and so on.

Also, after running the query the table should look like this:
Sample Data
----------------------------------------
http://whatever1
http://whatever2
http://whatever3
http://x.com/new/a.htm
http://x.com/new/b.htm
http://whatever4
http://x.com/new/c.htm
http://x.com/new/d.htm
http://whatever5
----------------------------------------

I am using mysql MySQL 4.0.25. Can anyone help me with a query to do this?

Thanks
Neville

Reply With Quote
  #2  
Old August 31st, 2005, 03:04 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
You'll be better off doing this in a script instead of trying to set it up directly in your database. Then you can use regular expressions to make the replacements much easier.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
  #3  
Old September 1st, 2005, 12:39 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
Hi,

Yes, i do realize that this is possible to do using a script however using a query is a lot more quicker than writing a script. Anyway, if its not possible then a script i guess is the only option.

Thanks
Neville

Reply With Quote
  #4  
Old September 1st, 2005, 10:00 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Using a query may lead to bigger errors.
I second the motion for a script.
Especially given that some of your data includes a domain name AND path already.

Reply With Quote
  #5  
Old September 1st, 2005, 10:33 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Assuming this can even be done with a query (which I'm not sure it can), it'll still be quicker to write a script than it will to set up and properly test a query, because in a script you can use regular expressions instead of the stacks of SUBSTRING()'s and LOCATE()'s you'd need in a query.

Reply With Quote
  #6  
Old September 1st, 2005, 05:22 PM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 3
Yep, a script is the best and quickest option. I could even beat the execution time of the (very difficult) query!
I wouldn't even start to write a query....

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Help Forumlate a Query...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway