简体   繁体   中英

Select a value on multiple columns using like

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?

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%'

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%')

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

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

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM