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.
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 ?);