1

I have a Table:

| USERNAME | FORNAME | SURNAME | TELNUMBER | ZIPCODE ....

and I want to search username forename and surname in 1 query / statement .. and I don't want multiple lines .. like.. lets say ..

username : maria33 forname : maria

so this should be 1 row .. when I search mar%

and not 2!

1 Answer 1

4

As a prepared statement:

SELECT *
FROM   users
WHERE  username LIKE ?
    OR forname  LIKE ?
    OR surname  LIKE ?

Then if you fill in all three parameters with the same string, "%mar%":

preparedStatement.setString(1, "mar%");
preparedStatement.setString(2, "mar%");
preparedStatement.setString(3, "mar%");

You'd end up with this SQL statement:

SELECT *
FROM   users
WHERE  username LIKE "mar%"
    OR forname  LIKE "mar%"
    OR surname  LIKE "mar%"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank .. and as a prepared statement ?

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.