Welcome to WebmasterWorld Guest from 54.159.214.250

Forum Moderators: open

using multiple SELECT * FROM WHERE url LIKE

   
3:18 pm on Jun 27, 2009 (gmt 0)

10+ Year Member



hello,

im cleaning up a database with links and because there are so many wrong ones i need to speed up my deleting process.

current im using like:
SELECT * FROM my_links WHERE url LIKE '%bla.com%'

but there are more urls to check....
like whatever.com , bla.com, etc....
all nlinks that contain private pages that i want out..

i tried :

SELECT * FROM my_links WHERE url LIKE '%bla.com%' AND '%bla2.com%' AND '%bla3.com%' AND '%bla4.com%' AND '%bla5.com%'

the list goes on..
i also used OR instead of AND..
a real sample of what i have is this:

SELECT * FROM my_links WHERE url LIKE '%chello%'
SELECT * FROM my_links WHERE url LIKE '%tiscali%'
SELECT * FROM my_links WHERE url LIKE '%lycos%'
SELECT * FROM my_links WHERE url LIKE '%versatel%'
SELECT * FROM my_links WHERE url LIKE '%web-log%'

meaning that i want to delete all urls that contain the above..
but how do i do it all together..?

3:56 pm on Jun 27, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



SELECT * FROM my_links WHERE url LIKE '%bla.com%' OR url LIKE '%bla2.com%' OR url LIKE ...

each expression has to be valid, you cannot run multiple values on "url LIKE " without a function or stored procedure (such as .. WHERE id IN(1, 2, 3), but to my knowledge, there's no such thing for LIKE)

4:02 pm on Jun 27, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



i also used OR instead of AND..

Or should have worked, did it not (with the changes J.H. noted?)

The only way I know to do this is script it, in the language of your choice. PHP example,

var $list = Array ('url1','url2','url3'); // etc
// You could put these in a text file or
// database field and read them in to
// populate the array

var $where='';


foreach ($list as $url) {
if ($where != '') { $where .= ' or'; }
$where .= " like '%$url%'";
}
if ($where != '') {
$select = "delete from table where $where";
// execute
}

echo your output before coding in the execute, just in case.

11:35 pm on Jun 27, 2009 (gmt 0)

10+ Year Member



thanks guys,...
janharders...the or url like worked...
so that did exactly what i wanted..
 

Featured Threads

Hot Threads This Week

Hot Threads This Month