Exercise: 45

Find all ship names consisting of three or more words (e.g., King George V). Consider the words in ship names to be separated by single spaces, and the ship names to have no leading or trailing spaces.

Solution

SELECT ship
FROM (
	SELECT name AS ship
	FROM ships
	UNION
	SELECT ship
	FROM outcomes
) all_ships
WHERE all_ships.ship LIKE '% % %'

References

  1. LIKE (Transact-SQL)

  2. Set Operators - UNION (Transact-SQL)