bbennett36
bbennett36

Reputation: 6355

Using a LIKE SQL statement in Express/Node

I have a SQL query that I am trying to call that searches for words that match a keyword and then searches within a radius for the results

This query will work but only searches using "LIKE ?" not "LIKE %?%

connection.query("SELECT *, ( 3959 * acos (cos ( radians(?) )* cos( radians( lat ) )* cos( radians( lng ) - radians(?) )+ sin ( radians(?) )* sin( radians( lat ) ))) AS distance FROM job_posting where job_title like ? HAVING distance < 25",
        [lat, lng, lat, keyword], function(error, result) {
        console.log(result)
    })  

but I need %% around the keyword value at the end, something like this

job_posting where job_title like %?% HAVING distance < 25"  

I can't get it to run the query with the % signs at all. Any tips on how to fix this?

Upvotes: 0

Views: 1474

Answers (1)

bbennett36
bbennett36

Reputation: 6355

var keyword = ("%" + req.query.keyword + "%")

Upvotes: 1

Related Questions