Recent

Author Topic: [SOLVED] MariaDB/MySQL not finding result in database  (Read 640 times)

DanishMale

  • Jr. Member
  • **
  • Posts: 76
[SOLVED] MariaDB/MySQL not finding result in database
« on: August 01, 2024, 03:24:52 pm »
Hi all,

I try to execute this SQL via ZEOS:

Code: Pascal  [Select][+][-]
  1. SELECT * FROM `tablename` WHERE LOWER(`column2`) LIKE LOWER('The%sample%is%made%by%me%');

Expected result from column1 would be 'Example'

However, I do NOT receive the expected result, even that column2 contains a recordset with 'The sample'

Database recordset looks like this

id   column1    column2
.....
23  Example    The sample
.....

« Last Edit: August 01, 2024, 06:15:12 pm by DanishMale »
Lazarus 3.4 x64 | Windows 10 x64 | Windows Server 2019 x64 | OpenViX 6.4.011 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 11.2 x64 | SQLite 3.40.0 x64 | PostgresSQL 16.3 x64

dseligo

  • Hero Member
  • *****
  • Posts: 1344
Re: MariaDB/MySQL not finding result in database
« Reply #1 on: August 01, 2024, 05:45:45 pm »
This has nothing to do with Zeos.
Where condition in your query expects words 'The', 'sample', 'is', 'made', 'by' 'me' in column2. If column2 would contain string 'The sample bla is bla made bla by bla me bla' then you'll get your row.
Or if you change your query to:
Code: SQL  [Select][+][-]
  1. SELECT * FROM `tablename` WHERE LOWER(`column2`) LIKE LOWER('The%sample%');

DanishMale

  • Jr. Member
  • **
  • Posts: 76
[SOLVED] Re: MariaDB/MySQL not finding result in database
« Reply #2 on: August 01, 2024, 06:14:42 pm »
Thanks  :D I was just hooked on an idea which according to your explanation won't work :D

And I found a "workaround"

Code: Pascal  [Select][+][-]
  1. SELECT * FROM `tablename` WHERE LOWER(`column2`) LIKE LOWER(SUBSTR('The%sample%is%made%by%me%',1,LENGTH(`column2`)));
Lazarus 3.4 x64 | Windows 10 x64 | Windows Server 2019 x64 | OpenViX 6.4.011 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 11.2 x64 | SQLite 3.40.0 x64 | PostgresSQL 16.3 x64

 

TinyPortal © 2005-2018