简体   繁体   中英

searching data using sql query

I have a simple sql query where I am trying to allow my employees to have the ability to search for other employees in my db. I want them to be able to search by both, or either first/last name. I have this, but it's not working.

 var selectEmployee = "select * from employees where UPPER(FIRSTNAME, LASTNAME) LIKE UPPER('%" + req.body.search + "%')" 

so how would I search through both first and last name using the req.body.search value I am passing back?

thanks.

Use OR

var selectEmployee = "select * from employees where FIRSTNAME LIKE '%" + req.body.search + "%' OR LASTNAME LIKE '%" + req.body.search + "%'"

you may use UPPER function

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