Ok so the main problem is a poorly designed php script.. but I cant do any thing about that right now..
So I turn to you for some help! :)
I want to list all items that start with "a%".. easy!.. well not here.. by default the search is made with wildcards "%string%".
SELECT DISTINCT `Select2` FROM `items` WHERE `Select2` LIKE "%a%"
And I canĀ“t change the search script... :/
Is there anyway that you can think of to get me around this problem?
There is no way to get around something hardcoded like that. But, since the results will include the results you are looking for, as well as substring matches, you can filter out the substring matches on the application side.
Related
I'm currently learning how to use web developer tools. So as a part of it I'm trying to find some multiple keywords at the search box which appears after pressing ctrl + F
My question is
How can I apply multiple search filters at a time uisng find. Like If i want to find more than 2 keywords in a source what is the best way to do it.
I've tried using regular expressions like so(I'm pretty sure syntax is wrong)
'Keyword1' & 'Keyword2'
Also tried
'Keyword1' | 'Keyword2'
Also tried
'Keyword1' or 'Keyword2'
But No use. I'm I missing anything here? I know we can use regular expressions but I'm looking for syntax to search multiple keywords. I'm pretty sure I've once used it a while ago . I don't remember exact expression to do so..
Using regex search, you can do: ^(?=.*foo)(?=.*bar).*$.
Source: https://stackoverflow.com/a/37692545/6911703
The syntax is
keyword1|keyword2|keyword3
without spaces and quotations
In my machine first I needed to turn off the regex feature before searching, and than turn it on again. o.w. it got stucked
I have a json which looks like this:
"{\"chat:title\":\"Random name Comunidad\",\"chat:type\":\"supergroup\",\"command:start:count\":4,\"command:start:ts\":1648146227630,\"command:help:count\":1,\"command:help:ts\":1648145742922,\"command:price:count\":3,\"command:price:ts\":1648146698585}"
And I'd like to query it and get the name out of it. I tried classically:
SELECT metadata->>'chat'
SELECT metadata->>'chat:title'
but it's not working. I think it's because of the backslash in the string... Any ideas how to query it?
Just remove backslash from the string:
with t as (
select '{\"chat:title\":\"Random name Comunidad\",\"chat:type\":\"supergroup\",\"command:start:count\":4,\"command:start:ts\":1648146227630,\"command:help:count\":1,\"command:help:ts\":1648145742922,\"command:price:count\":3,\"command:price:ts\":1648146698585}'
as metadata)
select replace(t.metadata, '\','')::json ->> 'chat:title'
from t
Is it of JSON type and the content is as is you showed? If so then:
select btrim(replace(metadata::text,'\',''),'"')::json->>'chat:title';
Manually removing the backslashes might work, but will eventually fail on some inputs and just make things worse.
The right way is to use the existing JSON operators to fix it (unless of course someone has already made it worse).
SELECT (metadata->>0)::jsonb ->> 'chat:title'
But really you should fix the source that is causing the problem, and update the existing data to store the fix.
update whatever set metadata=(metadata->>0)::jsonb;
If only some of the data has been crappified, you might need to where clause to distinguish the good from the bad and so only fix the bad.
I am trying to make sort of a search engine that searched through JSON values in my Database.
I have a table with a column called data in data there is a JSON string, example:
{"type_geld":"cash","bedrag":15.0,"totaal":8899.0,"reden":"itemshop-bought-item","citizenid":"EHT44095","steamnaam":"Finn"}
Now I want to search through the key steamnaam I am currently using this query:
SELECT * FROM logs_1 WHERE JSON_CONTAINS(lower(`data`), '"finn"', "$.steamnaam")
This does give me the rows that contain finn as a value in the steamname JSON.
But now I want to also make it check if it's not exactly the same, but almost the same. So basically a LIKE search. Can I achieve this with JSON_CONTAINS or something like that?
So if I type fin instead of finn I also want it to list the rows because it almost matches finn.
I tried a lot of things, but could not figure it out, hope someone has the solution for me! Thank you.
The solution I found:
Apparently after googling a bit more, I found this query, that exactly does what I want:
SELECT * FROM logs_1 WHERE JSON_EXTRACT(lower(`data`), "$.steamnaam") LIKE "%fin%"
The only concern I have if this will stay fast with a lot of rows..
SELECT *
FROM logs_1
WHERE data->>'$.steamnaam' LIKE '%fin%' /* COLLATE according CI collation */
I have some fields in a MYSQL database with the following content:
eq":"fieldname1+fieldname2+fieldname3+fieldname4/4
The numbers are always different, so it could also be something like:
eq":"fieldname11+fieldname22+fieldname8/10
I would like to run a query to achieve the following:
eq":"((fieldname1+fieldname2+fieldname3+fieldname4)/4, 2)
I currently have the following query
UPDATE wp_wrdydtdbww_cp_calculated_fields_form_settings
SET form_structure = REPLACE(form_structure, '???', '???')
WHERE id IN (1,2,3);
The problem is, that there are a lot of additional strings, containing 'fieldname' or '/' as well, so I need to replace the exact structure.
Can somebody help me to modify it?
I tried something with the LIKE pattern (%), but can't get it to work as I always replace other parts of strings as well.
Thanks!
I have been having trouble searching through a MySQL table, trying to find entries with the character (UTF-16 code 200E) in a particular column.
This particular code doesn't have a glyph, so it doesn't seem to work when I try to paste it into my search term. Is there a way to specify characters as their respective code point instead for a query?
Thanks,
-Ben
Not tested, but CHAR() could work for this:
CHAR(0x200E);
I can't set up a full test case right now, let us know whether it worked.