• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

AND/OR

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm creating a query based on two values entered by the user. If only the first value is entered, I'm creating a query based on that. If only the second value is entered, I'm getting the appropriate query. But when both are entered, I'm creating a query that says
select a.colA,b.colB,c.colD,d.colD from tableA a,tableB b,tableC c,tableD d where a.colA like ? AND a.colB like ?;
In the prepared statement, I'm passing the values for the colA and colB as "%"+colAvalue+"%" and "%"+colBvalue+"%".
So, this query gets rows if both the conditions match. But if I try to make it OR and run the query, I get a join,a Cartesian join,with A*B*C*D number of rows (with A rows in tableA,B rows in tableB,C rows in tableC and D rows in tableD). How can I modify the select statement so that I can achieve an OR operator and not AND ?
Am I missing something here ? Any suggestions will really be very helpful.
Thanks a lot.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to specify join criteria for each of the 4 tables you are including in your SQL. Something like:
select a.colA,b.colB,c.colD,d.colD from tableA a,tableB b,tableC c,tableD d where a.colA = b.colB and a.colA = c.colD and a.colA = d.colD and (a.colA like ? or a.colB like ?);
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a TON THOMAS, it worked. Gosh, its great to see responses to all questions here.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic