I have a database with some count of rows. They contains information about books. And I need to select books with Name which contain EXACTLY 5 numbers. I tried to select by
SELECT * FROM books WHERE Name LIKE “*#*#*#*#*#*”
But result by this query returning books with names which contain more than 5 digits
For example, I have some rows (Names of books):
- To Kill a Mockingbird 2
- 1984 2
- The Lord of the Rings (The Lord of the Rings, #1–3)
- The Chronicles of Narnia (Chronicles of Narnia, #1,2,3,4,5,6,7)
And query, what I need, must return 2 but not 4 item
Advertisement
Answer
So, that was very and very easy.
SELECT * FROM books WHERE Name LIKE "*#*#*#*#*#*" AND Name NOT LIKE "*#*#*#*#*#*#*"