User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 428,634 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,003 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 459 | Replies: 3
Reply
Join Date: Oct 2006
Posts: 128
Reputation: Barefootsanders is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
Barefootsanders Barefootsanders is offline Offline
Junior Poster

Selective deletes, help

  #1  
Jan 2nd, 2008
Hey everyone,

I'm attempting to delete records within my database but I'm having problems writing the query. What I need to do is delete records from my database that, within a field in this record, have a substring that I will pass to the mysql command. So for example,

A table has one field called filePath.
Example records:
C:\New Folder\test.txt
C:\New Folder\test1.txt
C:\New Folder\test1.txt
C:\Other Folder\test.txt
C:\Other Folder\test1.txt
C:\Other Folder\test2.txt

I would like to send a command that will delete records within the table where a substring of the filePath field matches 'C:\New Folder'. In this case, the top 3 records would be deleted.

Anyone know the proper syntax for a statement like this?

Thanks in advance.
-Barefoot
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Selective deletes, help

  #2  
Jan 2nd, 2008
And what have you tried so far that doesn't work?
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Oct 2006
Posts: 128
Reputation: Barefootsanders is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
Barefootsanders Barefootsanders is offline Offline
Junior Poster

Re: Selective deletes, help

  #3  
Jan 2nd, 2008
Ive read through mysql 5.0 documentation, tried using REGEX, LIKE, and strcmp(s1,s2) and nothing seems to work. I was wondering if maybe I missed something in the documentation.

Thanks.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Selective deletes, help

  #4  
Jan 2nd, 2008
Um, have you tried looking up the DELETE command? You will also want to qualify it with a WHERE clause, otherwise disaster is sure to follow. Try doing a SELECT ... WHERE first to make sure you are getting the right result set back, then swap the SELECT statement for a DELETE statement.

DELETE FROM your_table 
WHERE filePath LIKE 'C:\New Folder\%'
The '%' at the end of the search string is a wild card matching anything at the end.

You would do well to get yourself at least one good book on SQL in general, or MySQL if you can. Reading reference documentation for programs is like trying to learn how to speak a new language by reading a dictionary Look for 'MySQL' by Paul DuBois or for a general RDBMS book try 'Database Design for Mere Mortals' by Michael J. Hernandez.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 12:56 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC