w3resource

AdventureWorks Database: Address for city outside US starts with Pa

SQL Query - AdventureWorks: Exercise-49 with Solution

49. Write a SQL query to retrieve the mailing address for any company that is outside the United States (US) and in a city whose name starts with Pa. Return Addressline1, Addressline2, city, postalcode, countryregioncode columns.

Sample table: Person.Address


Click to view Full table

Sample table: Person.StateProvince


Click to view Full table

Sample Solution:

SELECT AddressLine1, AddressLine2, City, PostalCode, CountryRegionCode    
FROM Person.Address AS a  
JOIN Person.StateProvince AS s ON a.StateProvinceID = s.StateProvinceID  
WHERE CountryRegionCode NOT IN ('US')  
AND City LIKE 'Pa%' ;

Sample Output:

addressline1              |addressline2  |city                    			   |postalcode 			|countryregioncode|
--------------------------+--------------+-------------------------------------+--------------------+-----------------+
21105, rue de Varenne     |		 |Paris	 		 |75013	  |FR				|
22, rue du Départ	  |     	 |Pantin 		 |93500	  |FR				| 
36, avenue de la Gare     |     	 |Paris  		 |75019         |FR				|  
39, route de Marseille    |     	 |Paris  		 |75016	     |FR				|
98, rue Montcalm	  |     	 |Paris   		 |75019	  |FR				|
39, avenue des Laurentides|   		 |Paris La Defense       |92081|FR				|
3101, avenue de Malakoff  |    		 |Paris 		 |75003		|FR				|
9005, rue des Bouchers    |     	 |Paris 		 |75005	           |FR				|
...	

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Retrieve records contain green_ in a field.
Next: Fetch first twenty rows from the table.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

Ref : https://bit.ly/3VKT5M8