Sql comparison operators

From wikinotes
Revision as of 16:41, 6 March 2021 by Will (talk | contribs) (Created page with "= Regex = <source lang="mySQL"> ## Regex is treated fairly similarly wherever it is used ## (Even the different versions of regex). But for clarity here ## is the syntax that...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Regex

## Regex is treated fairly similarly wherever it is used
## (Even the different versions of regex). But for clarity here
## is the syntax that mySQL uses:
##
## .             --> any single character
## [A-z][0-9]    --> character range
## [0-9]*a       --> Matches any or no occurrences of [0-9]. 
##                         Can be used for single chars and char ranges
## ^a            --> matches lines starting with 'a'
## a$            --> matches lines ending with 'a'
## ^aaa$         --> matches 'aaa'. not '*aaa*' (which is default in mySQL)

SELECT * FROM userTable WHERE name REGEXP 'ghis'  # REGEX in sql query (implied '.*ghis.*' 
                                                  # on either side unless anchored with '^', or '$')

Like

## _                --> any single character
## %                --> any or no instances of character

SELECT * FROM my_table  WHERE name LIKE 'ghis%';  # SQL LIKE in sql query