-1

I have a query in SQL (Mysql) using a where clause.

SELECT * FROM TABLE WHERE name = 'Bristols';

Now I know that there's a row in the table containing Bristol's with an apostrophe, but not one without an apostrophe. However I want to return the row anyway. The problem is that I can only feed the query a value without an apostrophe: Bristols - is there any way within the query to remove the apostrophe from the field the query is searching?

4

3 回答 3

3
SELECT * FROM TABLE
WHERE replace(name, '''', '') = 'Bristols'
于 2013-08-23T13:38:42.517 回答
1

There are several ways to accomplish this:

See Fiddle

  1. Regex:

    SELECT  * 
    FROM    cities
    WHERE   name REGEXP 'Bristol\'?s';
    
  2. Replace:

    SELECT  * 
    FROM    cities
    WHERE   'Bristols' = replace(name,'\'','');
    
  3. Explicit Matching:

    SELECT  * 
    FROM    cities
    WHERE   name IN('Bristols','Bristol''s');
    
于 2013-08-23T14:15:15.770 回答
0

You have Two possible outlooks:

First:

 SELECT * FROM TABLE WHERE name LIKE '%Bristol%' // Gather data like: BrISTOLS, Bristols, Bristol, Bristol's,

Second:

  SELECT * FROM TABLE WHERE replace(name,'''','') = 'Bristols'
于 2013-08-23T13:55:12.083 回答