•
•
•
•
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
![]() |
•
•
Join Date: Oct 2006
Posts: 128
Reputation:
Rep Power: 3
Solved Threads: 1
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
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
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
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.
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.
DELETE FROM your_table WHERE filePath LIKE 'C:\New Folder\%'
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!"
"Others make web sites. We make web sites work!"
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the MySQL Forum
- Previous Thread: mysql logging
- Next Thread: How do I load MYSQL onto my website for my use?


Linear Mode