简体   繁体   中英

SQL SELECT WHERE statement. Concatenate attributes against value

First yes it's going to be on a silly database that should most likely get remodeled. I'm not able to do that for a long list of reasons at this point.

I have a list of members and they have a trainer which is written in a first and last name (I know you're screaming FK, I just can't)

However a trainer has a username but at this point that's in php so I'm using a string for this example. I want to compare the first and last name without spaces. I believe this is called concatenation. But I can't get it to work and I am unsure as to why.

I have this so far. (MYSQL)

SELECT firstname,lastname 
FROM member
WHERE firstnameTrainer + lastnameTrainer LIKE 'jakethompson'

MySQL, ORACLE

SELECT firstname,lastname 
FROM member
WHERE CONCAT(firstnameTrainer,lastnameTrainer) LIKE 'jakethompson'

using LIKE 'jakethompson' means case insensitive

using LIKE '%jakethompson%' means anything what contains this string

Use CONCAT :

SELECT firstname,lastname 
FROM member
WHERE CONCAT(firstnameTrainer,lastnameTrainer) LIKE '%jakethompson%'

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