Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLZOO - select from world tutorial #13

Tags:

sql

mysql

http://sqlzoo.net/wiki/SELECT_from_WORLD_Tutorial#All_the_vowels

Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.

Find the country that has all the vowels and no spaces in its name. You can use the phrase name NOT LIKE '%a%' to exclude characters from your results.

The query shown misses countries like Bahamas and Belarus because they contain at least one 'a'

I thought I could do this with more of a brute force method of nesting many OR statements but that didn't work and I'm not sure how to exclude a space from showing up.

like image 234
madman Avatar asked Nov 30 '22 09:11

madman


2 Answers

How to exclude the space

AND NOT LIKE '% %'
like image 44
ChrisG Avatar answered Dec 10 '22 03:12

ChrisG


You want all of the vowels in the word, so you need to use AND, not OR.

Also, to exclude something from the reply, you can use NOT LIKE. This exclusion condition counts in addition to all the vowel-conditions, so it too needs to be linked with AND.

If you can't solve it yourself, move your cursor over this block to see a valid solution:

SELECT name
FROM world
WHERE name LIKE '%A%'
AND name LIKE '%E%'
AND name LIKE '%I%'
AND name LIKE '%O%'
AND name LIKE '%U%'
AND name LIKE '%a%'
AND name LIKE '%e%'
AND name LIKE '%i%'
AND name LIKE '%o%'
AND name LIKE '%u%'
AND name NOT LIKE '% %'

(check this answer's sourcecode for a properly formatted solution)

like image 62
Philipp Avatar answered Dec 10 '22 03:12

Philipp