I want to join the sex of driver (from vehicle table), sex of casualty (from casualty table), speed limit (from accident table) and age of vehicle (from vehicle table) for accidents in a particular location code
I ran this code
stoke_accident = cur.execute("SELECT vehicle.sex_of_driver, casualty.sex_of_casualty, accident.speed_limit, vehicle.age_of_vehicle FROM accident JOIN vehicle ON vehicle.accident_index = accident.accident_index JOIN casualty ON accident.accident_index = casualty.accident_index AND vehicle.vehicle_reference = casualty.vehicle_reference JOIN lsoa ON accident.lsoa_of_accident_location = lsoa.lsoa01cd WHERE lsoa.lsoa01nm = 'Stoke Upon Trent';")
acc_list = stoke_accident.fetchall()
This is the SQL query:
SELECT
vehicle.sex_of_driver,
casualty.sex_of_casualty,
accident.speed_limit,
vehicle.age_of_vehicle
FROM
accident
JOIN
vehicle ON vehicle.accident_index = accident.accident_index
JOIN
casualty ON accident.accident_index = casualty.accident_index
AND vehicle.vehicle_reference = casualty.vehicle_reference
JOIN
lsoa ON accident.lsoa_of_accident_location = lsoa.lsoa01cd
WHERE
lsoa.lsoa01nm = 'Stoke Upon Trent';
I expected to get a list of the details I wanted – but got nothing …
3