Hi,I'm very new to SQL. I have access to the database at work and am trying to construct a query to aid some colleagues with an audit.The problem I've got is that I'm receiving a seperate set of results for each case query. I want each case query to be performed en bloc.I've created a fake script using two fictional tables:TABLES:-individuals table-person------John SmithJane Smith-incedents table-person events--------------------------------------------John Smith letter generatedJohn Smith seen off siteJane Smith letter generatedJane Smith seen on site
Query:select individuals.person, case (incedents.events) when 'letter generated' then '1' else '0' end as 'Letter?', case (incedents.events) when 'seen on site' then '1' when 'seen off site' then '1' else '0' end as 'seen?'from individualsinner join incedents on individuals.person = incedents.person
The output would look something like:person letter? seen?---------------------------------------------------------John Smith 1 0John Smith 0 1Jane Smith 1 0Jane Smith 0 1
But I want to be able to get output likeperson letter? seen?---------------------------------------------------------John Smith 1 1Jane Smith 1 1
The script I've got is far more complicated and the database has too many individuals to allow manual editing.I hope this is clear and that someone can help. Please ask for clarification if I've missed something important.Thanks.