MySQL replace multiple character - mysql

I need to fetch data from my MySQL database where one column is filled with strings that contains different quotes and apostrophes (‘, ’, ` and the classic one ').
In my search bar, I want to be able to only write the classic one ' and be able to search for that specific field wheter it contains ‘, ’ or `.
For example, I'd like to write "Regie de l'Angleterre" and that it automatically checks "Regie de l‘Angleterre" and so on.
Is that possible ?
How can I do something like this in SQL ? I tried to use REPLACE, but couldn't make it work with multiple
My where clause looks like this at the moment.
SELECT realestate_name FROM realestates WHERE REPLACE(realestate_name, ''','\'') LIKE %xxx%

SELECT realestate_name FROM realestates WHERE column LIKE '____'
Before you do that, change every single ' " ` and quotation mark and space to %, and put them on the ends
So it would look like this:
Regie de l‘Angleterre becomes: %Regie%de%l%Angleterre%
SELECT realestate_name FROM realestates WHERE realestate_name LIKE %Regie%de%l%Angleterre%
This will work & run fine with a not so large database. If you have millions of records, LIKE becomes a nightmare.

You can use multiple replaces in one select the Replace function returns string so you can call another one outside it. Like this
SELECT
realestate_name
FROM realestates
WHERE REPLACE(REPLACE(realestate_name, ''','\''),'’','\'') LIKE %xxx%

Related

Combining Remove and Replace Function in MS SQL Report Builder

A field gives me the following string:
#$TEXTA#$TEXTB#$TEXTC
I want to remove the #$-chars and seperate the values by a new line. In addition I want to replace special characters (&). In the end it should look like this:
TEXTA
TEXTB
TEXTC
So I use this code:
=Replace(Replace(Fields!My_Field.Value,"&","&"),"#$",Environment.NewLine)
The string starts with #$, so this code makes a new line in the beginning, which I want to avoid by using this code:
=Right(First(Fields!My_Field.Value, "DATASET"), Len(First(Fields!My_Field.Value, "DATASET"))-2)
I want to remove the first two chars before the replace function starts. My problem is, that I dont know how to combine these two functions to work properly.
Without testing this....
I think you should just be able to replace your reference to the field in your first expression, with your second expression, like this.
=Replace(
Replace(
Right(First(Fields!My_Field.Value, "DATASET"), Len(First(Fields!My_Field.Value, "DATASET"))-2)
,"&"
,"&"
),
"#$",
Environment.NewLine
)

SELECT Showing me a list with the name of the column and not the data inside

I have quite a strange problem, I'm very new to SQL and I was doing a free course in SQL
I'm actually learning the "SELECT" command.
So, I create my database, create some table, put some data in it with the "INSERT INTO" command
And now I want to select some data in it, but I have a strange bug (not an error) when i do
SELECT * FROM aliment;
everything work like it's supposed to do, but when I do
SELECT 'nom','calories' FROM aliment;
Something strange happens.
Instead have a list of all the specific data i'm looking to get i just get a list with all the data replaced by the name of the columns.
Here 2 screen to show you what's happens:
[2
I know one it's from the terminal(and yes it's not mine but from a video) and mine is from the software, but it's still had to work no?
You have a typo in your SQL. Use backticks (on the same key as ~ on a US keyboard) around your column names, not '. Using a single quote (an apostrophe) makes it a literal value, not a column name.
SELECT `nom`,`calories`FROM aliment;

Why do all my SQL queries have to be wrapped using the ` symbol?

I have been working on a database for my coursework and have used phpMyAdmin to build it. Now I am working on the queries using the query tool.
When I pick the tables and data I want to query and press "update query" it will generate the query which looks something like this:
SELECT `Customer`.`CustomerName`, `OrderDetails`.`Product`, `OrderDetails`.`QuantityOrdered`
FROM `Customer`
LEFT JOIN `Order` ON `Order`.`Customer` = `Customer`.`CustomerID`
LEFT JOIN `OrderDetails` ON `OrderDetails`.`Order` = `Order`.`OrderID`
This works fine and gives me the results I was expecting. However when I try and write my own query and put something like "SELECT Customer.CustomerName," WITHOUT the ' symbol it won't work and just throws up an error message.
Must I always wrap them using the ' symbol for the query to work?
Forward quotes are used to escape object names in MySQL. You don't have to use them unless you use names that wouldn't be valid identifiers - in this case, the table name order is a reserved word, and must be escaped. All the other tables and columns you're using seem to be OK.
Except for the visual nightmare and ability to create horrendous table names, backticks are entirely unnecessary. You will, however, be required to wrap any variables in single quotes.
As you can see from my example below, using backticks is not a requirement with PHPMYADMIN;
The reason it is not working when you remove the backticks is because you have a column called 'order'. Order is a keyword in SQL and therefore cannot be used as a column name without being wrapped in either quotes or backticks.

SQL NOT LIKE not functioning properly

I am unable to figure out why the NOT LIKE operators are not working properly. I have 34 sample_name in the database that start with NT but it only get rid of some, and not other. When I try searching with LIKE ('NT%), it search them all. Below is what I have.
WHERE
full.full_id IN ('272', '273')
OR full.full_id IN ('567', '686')
AND random.sample_name NOT LIKE ('NT%')
You have an extraneous , in the IN list and you are missing the ' at the end of your NOT LIKE statement. The statement should look like the following:
WHERE full.full_id IN ('272', '273', '567', '686')
AND random.sample_name NOT LIKE ('NT%')
You have several errors in the code you have posted. I am going to guess that you intend:
WHERE full.full_id IN (272, 273) AND
random.sample_name NOT LIKE 'NT%'
Notes:
No comma in the IN list.
Terminating single quote on LIKE pattern
Don't use single quotes for constants, if the column is a number (use single quotes only for string and date constants).
No parentheses are needed around the LIKE pattern (although that is not a syntax issue)

SQL Like query for each word containing keyword

E.g :
I have 1 word for search the data. And the word is 'ayam'.
And this is my query :
select nama_product from product where nama_product like %a%
It works fine. But it show the record that i dont want to be showed.
This is the result :
ayam bakar
daging ayam
bayam hijau
daun bayam
The first and the second result is okay. But the third and the last that i dont want to be showed.
Because i want to show 'ayam' not "b'ayam'"
How do i handle this? I don't know it is duplicate or not. Because i already search it but i didn't find.
If you need to search the word 'ayam' without any prefix and sufix character, you would better use regular expression for that .
e.g.,
SELECT namma_product FROM product WHERE namma_product REGEXP 'ayam'
try this. This will work
Unfortunately this is a limitation of SQL. Some SQL databases have advanced text searching functions such as regular expressions which allow very specific text results.
For your case you will likely have to perform multiple LIKE conditions. For example:
select nama_product
from product
where
nama_product like 'ayam %'
or nama_product like '% ayam %'
or nama_product like '% ayam'
or nama_product = 'ayam'
Please note that if the text fields are very large or if the table is large, queries that rely on LIKE operators can become very slow. LIKE does not scale well with large datasets. If this is a dataset you think will become very large in the future, best to design it in a way where the LIKE operator will not be needed.
You can use regex to match only whole words:
select nama_product
from product
where nama_product regexp '(^| )ayam( |$)';
(^| ) means the word must be the start of the string, or it must be preceded by a space
ayam is the word we're matching
( |$) means the word must be followed by a space, or it must be the end of the string
SQL Fiddle
when u insert '%' before and after it mean All Character before(after) your keyword so just change how u want
for example just keywords start with "ayam":
select nama_product from product where nama_product like 'ayam%'
another example just keywords ended with "ayam":
select nama_product from product where nama_product like '%ayam'
and after that look here ithink your answer is here :
Match only entire words with LIKE?