homepage Welcome to WebmasterWorld Guest from 54.204.79.235
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Adding an OR command in MySQL queries
itledi




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

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.

 

syber




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

$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

itledi




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

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?

jtara




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved