Questions here
- where postcode = 'KA%'
This will search for postcodes which contain the 3 characters KA% - and will match no records. You need to state:-
where postcode like 'KA%'
- where postcode like 'KA*'
This will not match any records, as the wrong wildcard character (*) has been used.
You need to state:-
where postcode like 'KA%'
- where last_donation_date like '01-Sep-%
You cannot use on a date a wildcard which is for string searches.
- where title = ('MISS','MRS','MS', 'Ms', 'Miss','Mrs')
A title cannot equal all of these different values. You need in:-
where title in ('MISS','MRS','MS', 'Ms', 'Miss','Mrs')
- where postcode between 'N1%' and 'N19%'
This is a bit more tricky. If you are using between, you are searching a range - and a range must have precised limits (eg from 1 to 5). Ranges of strings must have precise limits too, so you say:-
where postcode between 'N1' and 'N19'
- select urn
from pledges
where update_date > date('today') -'6 months'
OK, trick question. There's nothing wrong with this selection as such - but it will list all the people who have paid pledges in the last 6 months, even if the pledge has subsequently been deleted. If you want to exclude pledges which are deleted, add the following SQL:-
and pledge_status != 'D'
- select urn
from mailable_members
where raffles = 'N'
or country_code = 'SO'
and payments_per_year = 12
How will this be interpreted? As:-
where raffles = 'N'
or (country_code = 'SO'
and payments_per_year = 12)
or maybe:-
where (raffles = 'N'
or country_code = 'SO')
and payments_per_year = 12
This is a real example. Never leave it to chance - always put in brackets to make your meaning clear. The person who made this error ended up working for Greenpeace...