Mapinfo sql select several where

The SQL LIKE command enables a search based on a previously defined regular pattern instead of a fixed search term (as with SQL IN) or the definition of a range (as with SQL BETWEEN).

The SQL Like command is often used in texts or character strings in order to return results with regular patterns.

SQL LIKE command syntax

The SQL syntax a select query with WHERE and LIKE can be constructed as follows:

SELECT column-name FROM table-name WHERE column-name LIKE 'PATTERN'

The 'MUSTER' can be built up according to the following structures:

  • 'L_S': All strings that begin with an 'L', including a subsequent character and end with an 'S'.
  • 'BEST%': All strings that begin with 'BEST'.
  • '% UNG': All strings that end in 'UNG'.
  • '% ST%': All strings that contain the pattern 'ST' at any point.

SQL LIKE command example

Given a table called "Employees":

SurnameFirst namesalarygender
RichardJuliana1350w
wagnerJacob5790m
Rose crossMax4410m
LutterJuliane1271w
bollardMoritz5034m

Now we want to select all employees where the first name begins with R, has 8 characters and ends with z:

The SQL statement with the LIKE-Condition would look like this:

SELECT LAST NAME, FIRST NAME, SALARY, GENDER FROM EMPLOYEES WHERE SURNAME LIKE 'R________z'

The result would look like this:

SurnameFirst namesalarygender
Rose crossMax4410m

Now we want to select all employees where the last name begins with Lu:

The SQL statement with the LIKE-Condition would look like this:

SELECT LAST NAME, FIRST NAME, SALARY, GENDER FROM EMPLOYEES WHERE SURNAME LIKE 'Lu%'

The result would look like this:

SurnameFirst namesalarygender
LutterJuliane1271w

Now we want to select all employees where the last name ends in:

The SQL statement with the LIKE-Condition would look like this:

SELECT LAST NAME, FIRST NAME, SALARY, GENDER FROM EMPLOYEES WHERE SURNAME LIKE '% er'

The result would look like this:

SurnameFirst namesalarygender
wagnerJacob5790m
LutterJuliane1271w
bollardMoritz5034m

Now we want to select all employees where the first name contains the letters an:

The SQL statement with the LIKE-Condition would look like this:

SELECT LAST NAME, FIRST NAME, SALARY, GENDER FROM EMPLOYEES WHERE FIRST NAME LIKE '% an%'

The result would look like this:

SurnameFirst namesalarygender
RichardJuliana1350w
LutterJuliane1271w

Further articles