sqlbuilder icon indicating copy to clipboard operation
sqlbuilder copied to clipboard

Creating Where condition

Open devanshusharma19 opened this issue 6 years ago • 2 comments

Hi, can you help me for creating sql query in where condition

SELECT * FROM classicmodels.offices t1 INNER JOIN classicmodels.employees t0 ON (t1.officeCode = t0.officeCode) INNER JOIN classicmodels.customers t2 ON ( (t0.employeeNumber = t2.salesRepEmployeeNumber) OR (t0.firstName = t2.contactFirstName) ) WHERE (t2.creditLimit > 70000) AND (t2.creditLimit < 100000) OR (t0.officeCode = 6)

ORDER BY t0.firstName ASC

I am not able to create please tell me how to create AND or OR both condition in single query

WHERE (t2.creditLimit > 70000) AND (t2.creditLimit < 100000) OR (t0.officeCode = 6)

devanshusharma19 avatar May 21 '18 13:05 devanshusharma19

Hi,

I'd just put that whole expression in a single where call. Make sure you put parens around the whole thing in case you add other where clauses later. Also, I'd put parens around the and subexpression.

selectCreator
.where("(((t2.creditLimit > :p1) and (t2.creditLimit < :p2)) or (t0.officeCode = :p3))")
.setParameter("p1", 70000)
.setParameter("p2", 100000)
.setParameter("p3", 6);

jkrasnay avatar May 21 '18 22:05 jkrasnay

Hi, How can create dynamic query may more then one time AND condition or may be more then one time OR condition. it's condition comes random. then i want to create query. can you help me....

devanshusharma19 avatar May 22 '18 05:05 devanshusharma19