Find facilities by a name prefix

Question

Find all facilities whose name begins with 'Tennis'. Retrieve all columns.

Expected Results

facidnamemembercostguestcostinitialoutlaymonthlymaintenance
0Tennis Court 152510000200
1Tennis Court 25258000200

Your Answer

Your Results

Loading database...

Answers and Discussion

select * from cd.facilities where name like 'Tennis%';

The SQL LIKE operator is a highly standard way of searching for a string using basic matching. The % character matches any string, while _ matches any single character.

One point that's worth considering when you use LIKE is how it uses indexes. If you're using the 'C' locale, any LIKE string with a fixed beginning (as in our example here) can use an index. If you're using any other locale, LIKE will not use any index by default. See here for details on how to change that.