Blog

Query for Arab countries

  • 3 Jun, 2016
  • Phil Hong
  • 0 Comments

A client asked us to run a query in a database for all registrations where the person was from an Arab country. First, I had to look up which countries qualify as an Arab country. Here is that list:

Algeria
Bahrain
Comoros
Djibouti
Egypt
Iraq
Jordan
Kuwait
Lebanon
Libya
Mauritania
Morocco
Oman
Palestine
Qatar
Saudi Arabia
Somalia
Sudan
Syria
Tunisia
United Arab Emirates
Yemen

Next I had to construct a query that would look for the people who registered using these countries. Since we store the two character country code, I had to convert this list into a list of country codes. Here is the final SQL statement.

SELECT r.regdate, p.lastname, p.firstname, p.country
FROM `Registrations` AS r, `Persons` AS p
r.personid = p.id
AND p.country IN (
‘DZ’, ‘BH’, ‘KM’, ‘DJ’, ‘EG’, ‘IQ’, ‘JO’, ‘KW’, ‘LB’, ‘LY’, ‘MR’, ‘MA’, ‘OM’, ‘PS’, ‘QA’, ‘SA’, ‘SO’, ‘SD’, ‘SY’, ‘TN’, ‘AE’, ‘YE’)

Share This Story

Categories

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *