Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL search for "$" (dollar sign) fails?

Been asked to find dollar values across a large body of text. Can a search be performed on the dollar sign? If so, any examples/guidance would be most appreciated. Current query...

select * from concept where concept_description like '%$%';
like image 210
Atwp67 Avatar asked Oct 29 '25 01:10

Atwp67


2 Answers

You may want to use LOCATE to see if the col value contains the $ e.g.

   SELECT * FROM concept WHERE LOCATE('$', concept_description) > 0;
like image 120
Yogendra Singh Avatar answered Oct 30 '25 17:10

Yogendra Singh


The queries given will select the rows where concept_description contains a $, but I assume that you want to actually pull out the dollar amounts? If there's only ever just one dollar amount in a field it can be pulled out using

SELECT
SUBSTRING(
    concept_description,
    LOCATE('$', concept_description),
    LOCATE(' ', concept_description, LOCATE('$', concept_description)) - LOCATE('$', concept_description)
)
FROM table
WHERE LOCATE('$', concept_description) > 0

This assume that the dollar amount is always followed by a space, and might need some fudging on the indexes. It's probably best to pull the full field out with a simple query, then use regular expressions to grab any dollar values.

like image 34
Sammitch Avatar answered Oct 30 '25 17:10

Sammitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!