SQL LIKE |
SQL Sample Code - SQL LIKE Operator. |
Notes:- Wildcards are used a lot using the LIKE operator. Go to the Wildcards section to learn more
| SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern; |
See the SQL samples section below for an explanation of the LIKE operator
What does the SQL LIKE operator do? |
The SQL LIKE operator filters out columns based upon criteria specified with conditions which match a certain pattern.
Sample – SQL LIKE |
In this SQL sample we will use the database table ‘tblCompany’.
| Company_ID | CompanyName | Address | Town |
| 1 | SQL Sample | 1 Sample St | Hamburg |
| 2 | SQL Code Land | 2 Code Rd | Hamburg |
| 3 | Sample Code World | 66 SQL St | Curry |
| 4 | SQL Reference Ltd | 34 Reference St | Pisa |
| 5 | MySQL Code Geeks | 5 Sample Ave | Humberside |
In this SQL sample we want to retrieve all the Columns from the tblCompany table whose company has an Address beginning with ‘H’.
Use the SELECT statement below:
| SELECT * FROM tblCompany WHERE Address LIKE ‘H%’; |
The table of results will look like this:
Notes:- Wildcards are used a lot using the LIKE operator. Go to the Wildcards section to learn more.
| Company_ID | CompanyName | Address | Town |
| 1 | SQL Sample | 1 Sample St | Hamburg |
| 2 | SQL Code Land | 2 Code Rd | Hamburg |
| 5 | MySQL Code Geeks | 5 Sample Ave | Humberside |
Related SQL Sample Code:
|
|