EagleFox
EagleFox

Reputation: 1367

How to select exact value from sql statement

I have multiple records that start with "She" like "shepherd", "shell", "shelf"... I want to return records that has "she" with

SELECT records FROM MYTABLE WHERE records = 'She'

However this returns all data mentioned above... how can I return just "she' without the rest of the data?

Upvotes: 1

Views: 7962

Answers (2)

Bart Friederichs
Bart Friederichs

Reputation: 33531

To just select the ones that start with "she" (will also select records that start with "shephard" etc):

  SELECT records FROM MYTABLE WHERE records LIKE 'she%'

The ones that have the word "she" in it:

  SELECT records FROM MYTABLE 
      WHERE records LIKE 'she %' OR 
            records LIKE '% she %' OR 
            records LIKE '% she'

You could perhaps use regular expressions as well.

Upvotes: 1

ajtrichards
ajtrichards

Reputation: 30565

If you want to get the records where the word beings with "She" the query should be:

SELECT records FROM MYTABLE WHERE records LIKE 'She %'

Upvotes: 1

Related Questions