enriqg9
enriqg9

Reputation: 1507

SQL Select from DB where column like but doesn't start with '*'?

I have a DB as follows:

        name                ||        Country       ||   code
     Los Angeles                   United States          LAX
***Additional Services***         United Kingdom          999V
     New York                      United States          NYC

I want to select all values in the three columns that match a term but hide the ones that start with '*'. This is my sql to select any value from the three columns, I just need to add the part to skip the values that start with *.

SELECT code, name, Country FROM city_codes WHERE CONCAT(code, name, Country) LIKE '%$term%' ORDER BY name ASC

Upvotes: 0

Views: 1706

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1270421

Well, how about this?

SELECT code, name, Country
FROM city_codes
WHERE CONCAT(code, name, Country) LIKE '%$term%' and 
      code not like '*%' and name not like '*%' and country not like '*%'
ORDER BY name ASC;

Upvotes: 1

juergen d
juergen d

Reputation: 204854

Add to the where clause

and name not like '*%'

Upvotes: 0

Related Questions