0

My query looks something similar to COL1 = ? AND COL2 LIKE ? OR COL3 LIKE ? OR COL4 LIKE ? ..

and i pass the values of selection args as {"col1value","searchstring", "searchstring","searchstring"}

I am comparing if col2, 3 and 4 with same string . So can i optimize using binding to something like COL1 = ? AND COL2 LIKE ?2 OR COL3 LIKE ?2 OR COL4 LIKE ?2

so that i dont have to repeat the string in arguments {"col1value","searchstring"}

Is this possible and if yes what is the right syntax for it.

1

2 Answers 2

1

There are many ways of specifying parameters. To (re-)use a specific parameter number, append the number to the ?:

COL1 = ?1 AND (COL2 LIKE ?2 OR COL3 LIKE ?2 OR COL4 LIKE ?2)

(And AND has higher precedence than OR.)

Sign up to request clarification or add additional context in comments.

Comments

0

Try to this SELECT * FROM table_name WHERE searchstring IN(COL2, COL3, COL4);

In android select :

String select = "? IN (COL2, COL3, COL4)"

select args :

String[] args = new String[] {"searchstring"};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.