jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes MySQL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySQL question" Watch "MySQL question" New topic
Author

MySQL question

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 606

Is it correct to have an OR in the WHERE clause of a JOIN??


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44590
    
  34
Don't know. It sounds like the sort of thing which should be possible: try it. Beware of multiple joins however.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3749
    
  10

No it's terrible.

Lol. Actually it's fine to have but keep in mind database query optimizes tend to choke on disjunctive (= OR) query paths. In other words, the more OR's you have, the great the possibility its going to run poorly. There are often ways you can eliminate OR using boolean logic, so try to find one. Otherwise, if your query is especially large and uses OR, you might want to break it into multiple queries. This is a good example of syntax being perfectly fine, but in practice having issues.


[OCA 8 Book] [Blog]
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 606

Yes,it didnt give a syntax error but the performance was so bad that I thought it might not be a good practise....will try to use boolean logic.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySQL question
 
jQuery in Action, 3rd edition