hitesh.gawhade
hitesh.gawhade

Reputation: 347

How to search for a value with quotation marks in sql column and replace it?

In my sql table i have a column where i have values like :

enter image description here

I need to find these type of entries and remove single quotes as i dont need them, but how to fetch them through query in where clause ? If i use select * from table 1 where desc = 'the values is '10', it simply wont work as the statement is not correct. how can i modify my where clause to get desired result?

Upvotes: 0

Views: 9989

Answers (3)

try to use different quote types (double and single) inside and outside value. for example

SELECT * FROM table 1 WHERE desc = "the values is '10'";

or find all rows at once which contain single quote in desc

SELECT * FROM table 1 WHERE desc LIKE "%'%";

Upvotes: 0

user17441731
user17441731

Reputation: 1

You can also do:

select * from table 1 where desc like '%'%'

Upvotes: 0

kmkaplan
kmkaplan

Reputation: 18960

Double the quotation mark to escape it :

select * from table 1 where desc = 'i am ''not'' a graduate'

As a side note, don’t select *, explicitly list the columns you are interested in:

select id, "desc" from table 1 where desc = 'i am ''not'' a graduate'

… And don’t name your columns with SQL reserved words ;-)

Upvotes: 4

Related Questions