EDIT: Problem solved. It was my reading that was incorrect, not the SQL :p
Hi!
I was just reading in my database book about the LIKE SQL statement. It said this:
SELECT whatever FROM whereever WHERE 'Jeff' LIKE 'Jeff';
It continued to say that the statement 'Jeff' LIKE 'Jeff' would always return false. The book did not tell me why, nor can I find this anywhere else. Does this then mean that the following SQL also would return null?
SELECT W.name FROM whereever W WHERE w.name LIKE 'Jeff';
For reference, the book is: Database Management Systems: Ramakrishnan - Gehrke From McGRAW - Hill. International edition. ISBN 0-07-123151-X PAGE 140.
I took a look at that page (Amazon "search inside this book") and the key thing that you're missing is that the author is making a point there about whitespace. The book actually says
Thus, 'Jeff'='Jeff ' is true, while 'Jeff' LIKE 'Jeff ' is false.
Note the spaces!
Just to make it clear why the mistake occurred, here's the text:
Since the space is at the end of the line, it's hard to see. But as I say below, the quote mark wouldn't wrap to the next line if there were no space there.
MySQL would disagree with your book (not sure about other DBMSes):
mysql> SELECT 'Jeff' LIKE 'Jeff';
+--------------------+
| 'Jeff' LIKE 'Jeff' |
+--------------------+
| 1 |
+--------------------+
1 row in set (0.00 sec)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With