0

I have a query such as the below:

SELECT * from table_name where lastname regexp "[[:<:]]Smith[[:>:]]"

This returns

  • De Smith
  • Smith

I only need to retrieve Smith

I even tried the below

SELECT * from surnames where last_name regexp "[[:<:]][^\s]Smith[[:>:]]"
Alan Moore
  • 73,866
  • 12
  • 100
  • 156
Stackoverflow User
  • 161
  • 1
  • 4
  • 10

1 Answers1

1

I may be mistaking your requirement, but if you want to exactly match a last name then you can just use the equals operator:

SELECT * from table_name where TRIM(lastname) = 'Smith'

I used TRIM() on the lastname field just in case there might be leading or trailing whitespace.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360