Thanks again Glen. Yes, I want the query to list all the cities from the three city columns in the three different tables. I only want the cities thought that start with the letter A, B or C. I'm new to SQL though. How do I use a SubString or Between?
This is what I've tried:
When I have the
WHERE city LIKE '[A-C]%'
on just the last SELECT:
SELECT city "City"
FROM employee
UNION
SELECT city "City"
FROM customer
UNION
SELECT city "CITY"
FROM contact
WHERE city LIKE '[A-C]%'
ORDER BY city;
I get this list of cities:
CODE
+------------------+
| City |
+------------------+
| Acton |
| Acworth |
| Albany |
| Atlanta |
| Austin |
| Baltimore |
| Bedford |
| Belmont |
| Bohemia |
| Boston |
| Brooklyn Park |
| Buford |
| Burbank |
| Burlington |
| Cambridge |
| Carmel |
| Chattanooga |
| Chicago |
| Cincinnati |
| Clarksburg |
| Columbus |
| Concord |
| Dallas |
| Danbury |
| Denver |
| Detriot |
| Don Mills |
| East Douglas |
| Edmonton |
| Elmsford |
| Emeryville |
| Eugene |
| Fairfax |
| Fargo |
| Fort Wayne |
| Framingham |
| Ft. Wayne |
| Gloucester |
| Hartford |
| Houston |
| Hull |
| Huntington Beach |
| Jackson |
| Jacksonville |
| Kansas City |
| Knoxville |
| Lakewood |
| Landover |
| Laramie |
| LeCroix |
| Lexington |
| Lisle |
| Long Beach |
| Los Altos |
| Los Angeles |
| Madison |
| Mamaroneck |
| Manchester |
| Matthews |
| McLean |
| Miami |
| Middletown |
| Milton |
| Minneapolis |
| Miramar |
| Mississauga |
| Missola |
| Mogadore |
| Nashville |
| Natick |
| Needham |
| New Bedford |
| New Berlin |
| New London |
| New Orleans |
| New York |
| Newton |
| North Miami |
| North Potomac |
| Northbrook |
| Orlando |
| Overland Park |
| Paoli |
| Peoria |
| Plymouth |
| Port Washington |
| Powell |
| Raleigh |
| Reston |
| Rochester |
| Rutherford |
| Salt Lake City |
| San Francisco |
| San Jose |
| San Ramon |
| Santa Fe |
| Sarasota |
| Sioux City |
| South Laguna |
| Spokane |
| St Louis |
| St Paul |
| St. Louis |
| Stow |
| Stowe |
| Syracuse |
| Tacoma |
| Victoria |
| Waltham |
| Washington |
| Watertown |
| Wellesley |
| West Bloomfield |
| West Chicago |
| West Roxbury |
| Westerville |
| Westwood |
| White Plains |
| Wilmington |
| Winchester |
| Winnipeg |
| Winter Park |
| Wood Bridge |
+------------------+
123 rows in set (0.00 sec)
Those are all the cities in the "city" column in all three tables. Some of these cities are in three of the tables, some in two of the tables and some in only one table. The Unions seem to be filtering them correctly since it shows all of the cities only once. However, when I put the
WHERE city LIKE '[A-C]%'
in the last SELECT and the second SELECT:
SELECT city "City"
FROM employee
UNION
SELECT city "City"
FROM customer
WHERE city LIKE '[A-C]%'
UNION
SELECT city "CITY"
FROM contact
WHERE city LIKE '[A-C]%'
ORDER BY city;
it lists only these cities:
CODE
+--------------+
| City |
+--------------+
| Acton |
| Atlanta |
| Bedford |
| Belmont |
| Boston |
| Burlington |
| Cambridge |
| Concord |
| Emeryville |
| Framingham |
| Gloucester |
| Houston |
| Lexington |
| Long Beach |
| Milton |
| Natick |
| Needham |
| Newton |
| Stow |
| Waltham |
| Watertown |
| Wellesley |
| West Roxbury |
| Westwood |
| Winchester |
+--------------+
25 rows in set (0.00 sec)
Finally, when I put the
WHERE city LIKE '[A-C]%'
in all three of the SELECTs:
SELECT city "City"
FROM employee
WHERE city LIKE '[A-C]%'
UNION
SELECT city "City"
FROM customer
WHERE city LIKE '[A-C]%'
UNION
SELECT city "CITY"
FROM contact
WHERE city LIKE '[A-C]%'
ORDER BY city;
I get:
Empty set