SQL Lesson 3
SQL Lesson 3
2)
SQLBolt
(/)
(/)
When writing WHERE clauses with columns containing text data, SQL supports a number
of useful operators to do things like case-insensitive string comparison and wildcard
pattern matching. We show a few common text-data specific operators below:
= Case sensitive exact string comparison (notice the single col_name = "abc"
equals)
NOT LIKE Case insensitive exact string inequality comparison col_name NOT LIKE
"ABCD"
_ Used anywhere in a string to match a single character (only col_name LIKE "AN_"
with LIKE or NOT LIKE) (matches "AND", but
not "AN")
NOT IN (…) String does not exist in a list col_name NOT IN ("D",
"E", "F")
All strings must be quoted so that the query parser can distinguish words in the string
from SQL keywords.
We should note that while most database implementations are quite efficient when using
these operators, full-text search is best left to dedicated libraries like Apache Lucene
(http://lucene.apache.org/) or Sphinx (http://sphinxsearch.com/). These libraries are
designed specifically to do full text search, and as a result are more efficient and can
support a wider variety of search features including internationalization and advanced
queries.
https://sqlbolt.com/lesson/select_queries_with_constraints_pt_2 1/3
10/16/23, 11:23 AM SQLBolt - Learn SQL - SQL Lesson 3: Queries with constraints (Pt. 2)
Exercise
Here's the definition of a query with a WHERE clause again, go ahead and try and write
some queries with the operators above to limit the results to the information we need in
the tasks below.
Table: Movies
7 Incomplete
Cars SQL query John Lasseter 2006 117
RESET
Exercise 3 — Tasks
https://sqlbolt.com/lesson/select_queries_with_constraints_pt_2 2/3