File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySQL question" Watch "MySQL question" New topic

MySQL question

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 608

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

===>SCJP 1.5(72%)<===
Campbell Ritchie

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

Joined: Oct 23, 2005
Posts: 3753

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: 608

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.

I agree. Here's the link:
subject: MySQL question
It's not a secret anymore!