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 Ordering the Result Set

Gareth Powell
PLUS
Gareth Powell
Courses Plus Student 7,016 Points

Why did the wildcard operator "%" only pass when placed at end of string?

Hi Everyone,

Unless I have missed it, even after a few rewinds of the video, my code only passes when I place the wildcard operator "%" at the end of a string, as oppose to being placed at the start of a string.

To expand: does placing the wildcard operator "%" at the start of the string mean it will produce a different query result as oppose to when I place the wildcard operator "%" at the end of the string?

In sum, does the placement of the wildcard operator "%" effect the outcome of query?

Thanks

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

The video you are referring to does not say anything about this wildcard. Can you show the code you are asking about? The % wildcard will have a huge impact on the result. For example:

"%a" will return all strings that end with 'a' and have ANYTHING before that 'a' (any number of any characters).

"a%" will return all strings that start with 'a' and have ANYTHING after that letter 'a' (any number of any characters).

"a%a" will return anything that starts and ends with 'a' and has ANYTHING between those letters (any number of any characters).

http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

Gareth Powell
PLUS
Gareth Powell
Courses Plus Student 7,016 Points

Thanks Maciej Czuchnowski .

That has helped me a great deal and makes perfect sense.

Cheers, Gareth