Welcome to WebmasterWorld Guest from 54.204.162.36

Forum Moderators: open

Adding an OR command in MySQL queries

   
1:59 am on Mar 5, 2008 (gmt 0)

5+ Year Member



Hello,

I'm try to structure my query to allow for an or statement.

Original Query (Works)

$query=mysql_query("SELECT * FROM table WHERE url LIKE 'http://www.domain1.com%' AND requirements='met'");

Query with attempted OR Statements (Doesn't Work)

$query=mysql_query("SELECT * FROM table WHERE url LIKE 'http://www.domain1.com%' OR WHERE url LIKE 'http://www.domain2.com%' AND requirements='met'");

$query=mysql_query("SELECT * FROM table WHERE url LIKE ('http://www.domain1.com%' OR 'http://www.domain2.com%') AND requirements='met'");

$query=mysql_query("SELECT * FROM table WHERE url LIKE ('http://www.domain1.com%' ¦¦ 'http://www.domain2.com%') AND requirements='met'");

I tried searching for it, but the search engines don't like searching by OR.

Also, besides just using an OR, is there a better way to structure this? Eventually I would like to make the query run if one of ten urls are matched, but the number might grow in the future.

2:43 am on Mar 5, 2008 (gmt 0)

10+ Year Member



$query=mysql_query("SELECT * FROM table WHERE (url LIKE 'http://www.domain1.com%' OR url LIKE 'http://www.domain2.com%') AND requirements='met'");

Redundant WHERE clause, also should use parens when combining AND & OR

5:43 pm on Mar 18, 2008 (gmt 0)

5+ Year Member



Thank you very much, it works great, and I have now restructured my queries to use this format.

Now I'm concerned. If I have a long list of domains, the query is going to get huge. Will this cause some time of performance issue? Is there a way for me to make the list more managable, if nothing else than just for me looking at the code trying to edit it in the future?

5:46 pm on Mar 18, 2008 (gmt 0)

WebmasterWorld Senior Member jtara is a WebmasterWorld Top Contributor of All Time 5+ Year Member



I gather that you are mining some dataset that contains both your domains and others?

Sounds like you need a table with a list of your domains.

Then you can do a join between the tables, and select those records in the big table where the URLs are for your domains.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month