Its hard to work it out of course without knowing what the actual fact for each race is
BUT
If we assume that an all weather Ling races should have this data
d.race_type = 'Flat
d.track_type = 'Polytrack'
d.advanced_going = 'Standard'
h.race_type_id = 15
h.race_type = 'All Weather Flat'
h.going = 'Standard'
h.all_weather = 1
This will show all those who aren’t
select race_id , d.course,d.race_type,d.track_type,d.advanced_going,
h.course, h.race_type_id,h.race_type,h.going,h.all_weather
from daily_races d join historic_races h using (race_id)
where ( d.course = 'Lingfield' or h.course = 'Lingfield')
and race_type_id not in(1,13,14)
and
(d.race_type <> 'Flat' or d.track_type <> 'Polytrack' or d.advanced_going <> 'Standard'
or h.race_type_id <> 15 or h.race_type <> 'All Weather Flat' or h.going <> 'Standard' or all_weather <> 1) ;
Then we have to start adding some more where conditions
Like this, gives us 568 which don’t conform
select race_id , d.course,d.race_type,d.track_type,d.advanced_going,
h.course, h.race_type_id,h.race_type,h.going,h.all_weather
from daily_races d join historic_races h using (race_id)
where ( d.course = 'Lingfield' or h.course = 'Lingfield')
and race_type_id not in(1,13,14)
and
(d.race_type <> 'Flat' or d.track_type <> 'Polytrack' or d.advanced_going <> 'Standard'
or h.race_type_id <> 15 or h.race_type <> 'All Weather Flat' or h.going <> 'Standard' or all_weather <> 1)
and d.track_type = 'Polytrack';