I am making a python application to take data from an sql database. I am making it accept user input. If "all" is typed in, it will return all the data, if a specific country is stated then only that information will be returned. Even though I am specifying that Canada should only return the Canada data, it still returns all of the data. My sql query works, I already tried it.
I tried switching around the if and elifs but then it only returned the Canada data and nothing else.
def get_employees(mycursor):
while(True):
try:
print("\n-----------Employees Per Country-------------")
first_choice = input("Enter country name for specific country or (All) to view all countries:")
if first_choice == "All" or "all":
sql_query = "SELECT * FROM EmployeesPerCountry;"
mycursor.execute(sql_query)
query_result = mycursor.fetchall()
for record in query_result:
print(f"Country Name: {record[0]} \nNumber of Employees: {record[1]}\n")
return
elif first_choice == "Canada" or "canada":
sql_query = "SELECT * FROM EmployeesPerCountry WHERE country_name = 'Canada';"
mycursor.execute(sql_query)
query_result = mycursor.fetchall()
for record in query_result:
print(f"Country Name: {record[0]} \nNumber of Employees: {record[1]}\n")
return
except Exception as err:
print(f"An error has occured: {err}\n")
continue