1

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?

2
  • 3
    What RDBMS are you using? Please tag it. Commented Mar 27, 2018 at 12:31
  • 3
    You need to edit your question so you're asking for what you actually need or you're going to keep getting answers to the question you asked. stackoverflow.com/help/how-to-ask Commented Mar 27, 2018 at 12:39

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

yes and thank you ,but I want to use it in vb project for text edit, so like this it not working
@AbbasHodroj You could try something like this in Visual Basic: Dim sql As String = "SELECT * FROM your_table WHERE Description LIKE 'Mi%Bl%'". Not my domain though. Just giving you something I came across that you might find useful. Source: stackoverflow.com/questions/13583209/…
@AbbasHodroj: your comment makes no sense. The query solves the problem you stated in your question. I don't see why "a project for text edit" would make a difference.
0

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.

1 Comment

yes and thank you ,but I want to use it in vb project for text edit, so like this it not working
0
SELECT *
    FROM `table`
where Description like '%Mi% %Bl%'

1 Comment

yes and thank you ,but I want to use it in vb project for text edit, so like this it not working
0
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

5 Comments

That is invalid standard SQL
yes and thank you ,but I want to use it in vb project for text edit, so like this it not working
@a_horse_with_no_name Can you please explain me what is invalid in this SQL?
Backticks are invalid in an SQL identifier and string literals need to be enclosed in single quotes. Double quotes are for identifiers "Mi%Bl%" is a column name in standard SQL.
@a_horse_with_no_name Thanks! Changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.