I am stucked in one of MySQl query. I want two process on one field. Let say the field is named 'title'. Now title has BASE64_encoded data in it. Now I want to fetch all the data in lower case with mysql. I tried below code. but I didnt get my result. Hope you help me.
SELECT LOWER(FROM_BASE64(title)) as title FROM my_table;
I know, both are working individually. but not together. Now How can I do both process in one mysql.
I found solution.
SELECT LOWER(CONVERT(FROM_BASE64(title) USING latin1)) as title FROM my_table;
You can try like this:
SELECT LOWER(X) as title FROM (select FROM_BASE64(title) as X from my_table);
Related
i´m new in SQL and want to solve following case.
I have a table in a MariaDB named inventories. In this table are 2 columns: identifier and data.
I want to select and output a specific part in the column data, if the identifier is a specific one.
For example:
identifier
data
steam:xxxxxxxxxxxxxxx
...some data...,"Serial":"ZF3CJ8L1rrKjwP7nKTzb",...some more data...
The only part, that i want in the output is this: "Serial":"ZF3CJ8L1rrKjwP7nKTzb" but the part behind "Serial":" is a random value.
How can i solve this?
(i put a screenshot in here, table does not work for me in editorscreenshot of table in stackoverflow editor.)
You can try using the SubString function, which only returns a certain amount of character and starts a whatever character you want.
I got it!
SELECT (SUBSTRING(data, LOCATE('"Serial":"', DATA) + 0, 31)) FROM inventories where identifier = 'steam:xxxxxxxxxxxx';
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 a table with 3 columns something like below,
expert table
id - 1589
name - Jhonny
expert_in - 1,12,8 (Values similar like this)
The experts_in contains another table's foreign key
experts_in table
id - 1
expert_in - painting
I want search experts who are expert in some jobs while searching for experts
SELECT * FROM `experts` WHERE expert_in LIKE 1%
The above query brings all experts with 11,12,13...etc. I want only exact word. I know LIKE will bring all. Is there any way to achieve this without altering table. Thanks in advance.
You should use REGEXP. Try this query:
SELECT * FROM experts
WHERE expert_in REGEXP '[[:<:]]1[[:>:]]';
Output: See Live Demo on SQLFiddle
Note: You can adjust searching string based on your requirement above REGEXP is searching exact word.
if you can alter the data (not the table/schema) you should append and prepend another comma, so you can search with where col like "%,123,%", this will always fit on an exact value. Otherwise you have to use regex with something like ,?123,?
I have a table field events which can contains:
Only a sequence of number, for example: 45
or a sequence of number divided by the symbol |, for example 55|65|76
I think i have to use LIKE, but i don't know how. Can you help me?
Thanks
I would recommend using CONCAT to add a pipe | before and after your field, and then using a LIKE search. Something like this:
SELECT *
FROM YourTable
WHERE concat('|',field,'|') like '%|45|%'
SQL FIddle Demo
However, I highly recommend trying to normalize your data. Considering storing these in separate rows which would make searching/maintaining much easier.
To fix your query, use:
Select * from tbl where events='45' or events like '%|45' or events like '%|45|%' or
events like '45|%'
but this is terribly slow and should not be used.
Instead, do as Marc B states and create a child table events (ID, event).
I would like to SELECT a table row by searching a Blob's hex string value. I have a blob value that I want to find whose hex representation is 0041b074351bfa1092fd740c146f26ae. I would like to able to SELECT for this row by typing all or part of the string. Is this possible?
Try this:
SELECT *
FROM t1
WHERE UNHEX(hex_col) LIKE '%value%';
ps: It can be really slow when comes to performance. Be careful.
;-)
Simple query is working fine for me.. Please try like this
EG.
SELECT *
FROM YOUR_TABLE_NAME_HERE
WHERE YOUR_BLOB_FIELD_NAME_HERE LIKE '%SEARCH_TEXT_HERE%'