Friday 15 March 2013

mysql - How to search for substring in one of two fields of a table -



mysql - How to search for substring in one of two fields of a table -

i have table 3 columns: id, first, , last.

i'd find records 'sam' in either first or lastly field.

i'm not expert mysql, seems me 1 field queried using like operator.

how can utilize like in query info both columns @ same time?

i've tried this:

select id `employees` 'first' 'sam' or 'last' 'sam'

but message "you have error in sql syntax; check manual corresponds mysql server version right syntax."

i can't seem figure out why getting syntax error, 1 problem query putting single quotes around column name causes treated string literal instead of column name.

what mean instead of comparing value in first column string 'sam', it's comparing 2 strings, 'first' , 'sam' different. query homecoming no results.

in addition, work if first or lastly name equal sam. check characters substring @ point, add together wildcards @ front end , of strings.

try this:

select id employees first '%sam%' or lastly '%sam%'

here sql fiddle show how works.

mysql sql

No comments:

Post a Comment