SQL wildcard question

Sorry, I'm new to working with databases - I'm trying to execute a query that will get all characters that look like a string in SQL.

For instance,

If I search for all users that start with a specific line, something like S * or Sm * that will return "Smith, Smelly, Smiles, etc."

Am I on the right track with this?

Any help would be appreciated and thanks in advance!

+5
source share
6 answers

The LIKE statement is what you are looking for, so for your example, you need something like:

SELECT * 
  FROM [Users]
 WHERE LastName LIKE 'S%'

The symbol '%' is a wild-card in SQL.

+6
source

Sql cannot do this ... placing the percent symbol in the middle.

SELECT * FROM users WHERE last_name LIKE 'S%th' 

where and.

 SELECT * FROM users WHERE last_name LIKE 'S%' and last_name LIKE '%th' 
+5

SELECT * 
  FROM [Users]
 WHERE LastName ='Smith'

, , blasmith, smith2 .. ..

SELECT * 
  FROM [Users]
 WHERE LastName LIKE '%Smith%'

, , ,

SELECT * 
  FROM [Users]
 WHERE LastName LIKE 'Smith%'
+3

(ANSI) SQL LIKE:

  • _ (). .
  • % ( ). .

, SQL Server LIKE, , :

  • [ ]
  • [^ ] .

:

  • [0-9] .
  • [A-Z]
  • [^ A-Z0-9-] , , .

, , . .

, ('[]'), . , .

where x.field like 'x[[][0-9]]'

, "x [0]", "x [8]" ..

where 'abc[x' like 'abc[x'

.

+2

.

, :

 SELECT * FROM users WHERE last_name = 'Smith'

, , "S" "th", LIKE :

 SELECT * FROM users WHERE last_name LIKE 'S%th'

( , SQL- "%", "*" ).

"", SOUNDEX. ( ).

0

SOUNDEX, .

select * 
from [users]
where soundex('lastname') = soundex( 'Smith' )
or upper(lastname) like 'SM%'
0

All Articles