views:

40

answers:

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 dont want multiple lines .. like.. lets say ..

username : maria33 forname : maria

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

and not 2 !

+3  A: 

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%"
John Kugelman
Thank .. and as a prepared statement ?
darkrain