1

i have a names table containing 4 columns

id     fname      mname     lname
1      rain       santos    reyes
2      rocky      blunt     simon
3      greg       hammer    go

then i want to select a particular name from the columns fname, mname and lname using this select i did

Select * from account like 'rid%' IN(fname, mname, lname)

but it went error. im not really sure with the code.

how could I select a specific like value in the fname mname and lname columns?

Kara
  • 6,115
  • 16
  • 50
  • 57
user3117337
  • 213
  • 1
  • 5
  • 17

3 Answers3

0

You need to check each column individually and then use OR between each one to allow the variable to be in any of the three columns:

SELECT * FROM account 
    WHERE fname LIKE 'rid%' 
    OR mname LIKE 'rid%'
    OR lname LIKE 'rid%'
Styphon
  • 10,304
  • 9
  • 52
  • 86
  • this doesnt take effect sir when i search a value from a post method? – user3117337 Jan 22 '14 at 16:43
  • @user3117337 I'm sorry, I don't understand what you mean. If you still have issues update your original post with more detail and any errors. – Styphon Jan 22 '14 at 20:30
0

For LIKE clauses, you have to use OR and separate each condition, like so:

SELECT *
FROM account
WHERE (fname LIKE 'rid%'
       OR mname LIKE 'rid%'
       OR lname LIKE 'rid%')
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
-2

You miss some keywords and have an incorrect syntaxis. Try this one:

SELECT * FROM `account` WHERE "rid%" IN ( `fname` , `mname` , `lname` )

Regards.

erv-Z
  • 87
  • 1
  • 5