SQL query returning an empty set

I have this table

| BookID | BookTitle                      | NumberOfPages | NoOfCopies |
+--------+--------------------------------+---------------+------------+ 
|      1 | The Help                       |           444 |          4 |
|      2 | The Catcher in the Rye         |           277 |         10 |  
|      3 | Crime and Punishment           |           545 |          2 |
|      4 | The Brothers Karamazov         |           795 |          1 |
|      5 | A Crown of Wishes              |           369 |         12 |
|      6 | The Fireman                    |           752 |          3 |
|      7 | Fahrenheit 451                 |           174 |          9 |
|      8 | The Hobbit                     |           366 |          1 |
|      9 | Lord of Emperors               |           560 |          4 |
|     10 | Holy Bible: King James Version |          1590 |         11 |
----------------------------------------------------------------------------

When I insert the name of the book and expect it to return the identifier of the book, it always returns an empty string so far I have tried these queries .-> book_info is the name of the table:

select BookID from book_info where ucase(BookTitle) = ' THE HELP% ';
select BookID from book_info where BookTitle = ' The Help   ';
select BookID from book_info where lcase(trim(BookTitle) = 'the help';

but none of them worked.


Note. I do not rely on sql in my work.

+4
source share
2 answers

you need to use, for example, if you want to use "%"

when you use "=", you need to make sure that it is the same. even space is also considered

  select BookID from book_info where BookTitle LIKE 'THE HELP%';
+2
source

, , , , = , :

select BookID from book_info where ucase(BookTitle) = ' THE HELP% ';
select BookID from book_info where BookTitle = ' The Help   ';
select BookID from book_info where lcase(trim(BookTitle) = 'the help';

:

MySQL .

, .

% LIKE :

select BookID from book_info where ucase(BookTitle) LIKE '%THE HELP%';

LIKE %THE HELP% THE HELP ;

+2

Source: https://habr.com/ru/post/1676052/


All Articles