?
Solved

How to search a string in a mysql text field

Posted on 2014-03-07
4
Medium Priority
?
957 Views
Last Modified: 2014-03-07
Hello,

I need to search a string in a mysql text field that could contains newlines chars. Using the standard LIKE operator it does not work because the string searched is different from the text field as it contains newlines.

Here is an example:
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device. Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

the string could not be found because the text field is:

Fineco App. Tutti i servizi, in tutti i device.
Da dove preferite collegarvi?

https://welcome.fineco.it/bancaonline/extra/fineco-app

So I think there should be e method to search removing newline chars.

thank you
0
Comment
Question by:apedic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39912021
Try
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device.\n Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

or
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device.\r\n Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

if the text is from Windows.

HTH,
Dan
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39912023
Or
SELECT id FROM fb_posts WHERE REPLACE(message,"\n","") LIKE '%Fineco App. Tutti i servizi, in tutti i device. Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

0
 

Author Comment

by:apedic
ID: 39912074
thank you, works perfectly!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39912093
Glad I could help!
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question