MySQL - Populate a field based on part of another field - mysql

I have a table where one column, named Description, has a variety of information all crammed together. Part of that information is an abbreviation for a vehicle maker. For example, the Description column could read "6cylM.Benz32zy,.026L"
I want to populate a new Vehicle column with Mercedes Benz wherever the Description column contains M.Benz somewhere inside. The key word there is "somewhere"; the abbreviated vehicle name could be anywhere in the description field.
So far I have the following code. However, MySQL tells me it can't find the %M.Benz% column. I'm not trying to look for a column named %M.Benz%, I'm trying to find TEXT that is %M.Benz%.
UPDATE tbl_arcore_repuestos
SET Vehicle = `Mercedes Benz`
WHERE Description LIKE `%M.Benz%`;
Any ideas? Most of the other solutions on StackOverflow to similar questions rely on the sought-after text being in a fixed position (like at the beginning of the string or separated by a consistent character). The text I'm looking for could be ANYWHERE in the Description column.

Have you missed the quotes or used backticks instead of quotes?
UPDATE tbl_arcore_repuestos SET Vehicle = 'Mercedes Benz' WHERE Description LIKE '%M.Benz%';

Related

How to use SQL to find specific names or words in a database?

I am working with a database of data from Reddit. I want to find the name and description of all subreddits where the name starts with "covid" or "corona" and the description contains "covid" anywhere. I then want to output a table that has two columns: name and description.
So far, I have tried this SQL code:
select
subreddit AS name,
subreddit AS description
from
subreddit
where subr_description like "%covid%" "%corona%";
When I execute, I get an output of the table with the appropriate columns: name and description but they are empty, no data.
How can I have the table with the right columns populated with the right data please?
It looks like you need to adjust the column names that you're selecting instead of subreddit AS x twice. I'm not sure if you even have a column named subreddit or not, but that also appears to be the table name, which is confusing.
Then you can adjust the logic in the WHERE to check your two conditions:
SELECT
subreddit AS name,
subr_description AS description
FROM
subreddit
WHERE
-- name starts with covid or corona ("text%")
(subreddit LIKE "covid%" OR subreddit LIKE "corona%")
-- description contains covid ("%text%")
AND subr_description LIKE "%covid%"

Search for a value on a database column splitting the value where there is a blank space

I have a table on my database named leads. Inside that table there are several columns containing the name, telephone, address, postal code etc, etc... of the leads.
The column that contains the name of the leads is called clientName. As an example we have Loyalty Logistics.
I have an input type text inside a form where users search for a specific client name and shows the results on a Popup. Right now I am using a WHERE clause
....WHERE leads.clientName LIKE "%'.$_POST["keyword"].'%"
The way it is right now it will only show up the client Loyalty Logistics
if the user type Loyalty or Logistics or Loyalty Logistics, but in the case the user made a mistake and typed Loyalti Logistics I would also like to be able to show on the results all the clients that contained Logistics on its name.
You can make the split with your server side language (PHP, Python, JS ...) and obtain a list of keywords and make your sql request with it.
keywords = split(keyword)
for key in keywords
....WHERE leads.clientName LIKE "%'.$_POST["key"].'%"
I hope it will be helpful.

SQL replace any number

I am in MySql. I have the table named blog and the column photo. I want to make some changes for instance. All the values in that column have that schema:
nunber/text.svg
For instance: 1/marketing.svg
I want to delete the number/
In the example, I want to have: text.svg.
But I want it work with any number, one, two or three digits.
This is what I tried
UPDATE blog
SET photo = REPLACE(photo, '%/', '')
If the string format is consistent, i.e. a number followed by a / and then the text, you can use a combination of substring and locate to update the column.
UPDATE blog
SET photo = SUBSTRING(photo, LOCATE('/',photo)+1)
WHERE LOCATE('/',photo) > 0

Solr field:needle or q=needle&qf=field different results

Let's say I'm trying to search for 'Douglas' in any field. If I just do:
solr/query?q=Douglas
I get 0 responses, but if I do:
solr/query?q=firstname:Douglas
then I do get responses, why is this? I've also tried:
solr/query?q=Douglas&qf=firstname
which still gives me nothing. How do I just do a search for all fields? Then how do I 'boost' the relevancy of some fields? For example, if I search for Douglas, then people called Douglas should come up before items with the word 'Douglas' in their description.
You've got two concept mixed up here.
The default search goes against one field. That's the field defined by df (default field) parameter (not qf). So, solr/query?q=Douglas&df=firstname should have worked. Solr examples usually have text field set as default and copyField instructions to copy other fields into that. This works, but does not allow to use different analyzers for different fields. Nor does it allow ranking based on which field content is found in.
If you want to search multiple fields with different weights, you need to switch to dismax or edismax query parser. Then, you do use qf parameter to show which fields to search through.
You can experiment with all of that in the Solr Admin UI.
You have to use copyfield to copy your field into text to make it searchable. In default, all fields values which wanna searchable will copy into text field. You have to add a copy field as here or here
To add boosts at query time:
q=(firstname:douglas)^100 OR (body:douglas)^50 OR (someField:douglas)^25

Fields interactions in Access

Okay, I got a Access database with 1 table (lets call it sectorDescriptions) who contain two column, one who contain the code of all the sectors of activity and the other who contain the name of the sector of activity. Then I got another table (lets call it... ClientInfo) who contain MUCH MORE column but one of those column which is a dropdown list who contain the code of the sector of activity from the table of sectorDescriptions. Now heres my question, I made a form out of the table ClientInfo and now I want that when the user pick a new sector code from the dropdown list, the box named sector name change to the matching sector name based on the sector code! LOL worst question's formulation ever! Sorry for that but I am tired and I'm not really good in english!
Your combo box (cboFilter in this example) should have recordset property something like this:
SELECT [sector code], sectorDescriptions FROM sectorDescriptions ORDER BY [sector code];
If you don't want people to see the Description, just set the column width to 0"
On the after update event of your combo box, put something like this:
Me.txtDescription = Me.cboFilter.Column(1)