Abbas Hodroj
Abbas Hodroj

Reputation: 11

SQL query to search for a field by multiple values in same field

For examples :

ID - Description

01 - Mix Black
02 - Mix Red
03 - Mix Blue

How I can write a query to show the field like "Mi Bl" in a query?

Upvotes: 1

Views: 142

Answers (4)

Ronan Boiteau
Ronan Boiteau

Reputation: 10138

You can use LIKE with %:

SELECT * FROM your_table WHERE Description LIKE 'Mi%Bl%';

This query would give you these 2 results:

01 - Mix Black
03 - Mix Blue

% is a wildcard:

The percent sign represents zero, one, or multiple characters

More information on LIKE.

Upvotes: 1

Raj
Raj

Reputation: 716

SELECT * 
FROM Tablename 
WHERE `Description` LIKE 'Mi%Bl%';

'%' character is used to match any number(0, 1 or more) of characters. So this will match to your below records and result set will be -

ID - Description
-------------------
01 - Mix Black
03 - Mix Blue

Upvotes: 0

Rubin Porwal
Rubin Porwal

Reputation: 3845

SELECT *
    FROM `table`
where Description like '%Mi% %Bl%'

Upvotes: 0

Eric Brandt
Eric Brandt

Reputation: 8101

Use a LIKE clause with wildcard characters. https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql

SELECT *
FROM YourTable
WHERE Description LIKE 'Mi%Bl%';

This is SQL Server syntax, but any RDBMS will have a similar wildcard you can use.

Upvotes: 0

Related Questions