Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Database Foundations Reading Data from Databases with SQL Querying Tables

Seth Warner
Seth Warner
5,348 Points

OKay so why exactly would you just not use the % right off the bat..also

if you did not feel like you needed a "wildcard feature"(%), then why even use the Claus/keyword LIKE, and just type it directly as the title. I just don't understand why you would use LIKE without %, seeing that it requires % to really use it. I must be missing the reason to use LIKE without the %("wildcard", option).

1 Answer

Codin - Codesmite
Codin - Codesmite
8,600 Points

= Compares the entire string. LIKE compares one character at a time. As far as I know = is faster and less resource heavy then LIKE.

Another example:

CREATE TABLE #temp (nam [varchar](MAX))
INSERT INTO [#temp] ([nam])
VALUES ('hello')
INSERT INTO [#temp] ([nam])
VALUES ('hello  ')

SELECT * FROM #temp WHERE [nam] = 'hello  '

SELECT * FROM #temp WHERE [nam] LIKE 'hello  '

The first SELECT query will return both rows but the second SELECT query will only return one row. Trailing spaces are significant with LIKE but not with =.