![]() SQL database system |
WHERE clauseThe SELECT, UPDATE, and DELETE commands involve the use of a WHERE clause to select rows. shsql's WHERE clause syntax does not conform to SQL standards and is somewhat simplistic. Nevertheless, it is reasonably powerful and flexible.Examples
Interaction with indexingFor data tables for which indexes have been created, the WHERE clause plays an important role in the index access operation. Many (but not all) comparison operators can exploit indexes. More info.ComparisonsA where clause contains one or more comparisons. Comparisons usually have a database field specified on the left hand side, an operator in the middle, and a constant is on the right hand side. Comparisons must be structured this way is indexing is involved; otherwise the constant may be on the left if necessary (such as when getting wild card patterns from the database for comparison against a constant using LIKE).shsql supports the following comparison operators in WHERE clauses. Some operators have one or more alternatives that may be used if desired.
shsql also provides the following operators which are not part of standard SQL (some of these are available as functions in other SQL implementations). See also the examples above.
Alpha vs. numeric= and != can be used with any data.IN, !IN, INLIKE, and !INLIKE are intended for alphanumeric strings. However since shsql is typeless, these operators can be used similarly with numerics eg. id in "20,28,35" or id like "40*". If the comparison database field is indexed, the index should must be built as alpha, not numeric, in order for this to work.
Numeric-only comparison operators are: > >= < <= INRANGE OUTRANGE.
If the comparison database field is indexed, the index must be built with
ORDER = NUMERIC
in order for numeric comparisons to work properly.
Case sensitivityThe = and != operators are case sensitive. The other operations are case insensitive. To do a direct case-insensitive comparison use LIKE instead of =.ListsThe IN, INLIKE, and INRANGE comparison operators (as well as their inverses) take a comma-delimited list as the right side operand.For IN and INLIKE (and inverses) the list should be enclosed in quotes, NULL is permitted as a list member, and individual members may contain embedded spaces, which will be considered part of the individual. Zero-length members are ignored; if the entire list is a zero-length string it is taken as NULL. For INRANGE and OUTRANGE, the values are numbers, the list should not be enclosed in quotes, should not have any NULL members, and should not contain any embedded whitespace. The examples at top of this page include some that use comma-delimited lists. Note that the CONTAINS operator can also be used with comma-delimited lists, however "words" are delimited not just on commas but on any whitespace or punctuation.
Sometimes SELECT DISTINCT is in effect automatically when list comparison operators are used
on indexed fields.. see the notes at the end of the
indexes manual page.
Wild card charactersWild card matching may be done using LIKE, !LIKE, INLIKE, and !INLIKE. Wild card characters are * which matches any number of any character, and ? which matches a single instance of any character. Matching is case-insensitive. Full-fledged regular expressions capability is not implemented, and use of the * character is limited to the following positions: *abc, abc*, ab*cd, and *abc*. ? may be used anywhere. (% may be used rather than * by setting dbwildcard in your project config file. )NULL handlingDescribed here.Searching text fieldsThe CONTAINS operator allows multiword fields to be searched using a "search engine" syntax.Compound conditionals, and presidenceA compound conditional is two or more conditionals that are connected using the AND and/or OR logical connectors:
Presidence: compound conditional expressions are evaluated by splitting into OR terms, and then evaluating each term starting with the leftmost. For example:
shsql does not allow presidence to be altered by use of parentheses. The provided operators such as IN, INLIKE, INRANGE and OUTRANGE may be useful in eliminating lower-level ORs. It may also be helpful to capitalize ORs to emphasize their presidence.
SELECT DISTINCT will be in effect automatically when OR is used
with a query involving indexed fields.. see the notes at the end of the
indexes manual page.
Functions and arithmetic expressions
These are not supported in shsql WHERE clauses.
|
![]() Copyright Steve Grubb |