We continue a tour of SQL querying and look at a solution to the HMRC’s woes
To identify people for whom we don’t know certain information, IS NULL works
with numeric or text values, like this:
WHERE ChildNo IS NULL;
(Q10)
WHERE HomeTown IS NULL;
(Q11)
Further operators
There are also three logical operators that are processed after any of the
operators in the list above (though it is possible to alter the order in which
they’re performed by the use of brackets). We could write:
WHERE ChildNo=2 OR ChildNo=4;
(Q12)
to find people with two or four children. We get an answer if either one of
these conditions is met, as you can see in:
WHERE ChildNo=2 Or ChildNo=8;
(Q13)
There are no people with eight children but the query still returns the rows
for those with two. Hopefully you should be able to work out what these next two
queries do by now. Try to guess the output before running them:
WHERE ChildNo=3 AND 4
HomeTown=’London’;
(Q14)
WHERE ChildNo=3 AND NOT 4
HomeTown=’Leeds’;
(Q15)
As you can see, SQL operators and predicates can add immense flexibility to your queries.
Head for the hills…
O’Reilly’s Head First series aims to make the learning process engaging and
entertaining – a truly laudable goal. But applying a formula – graphics,
diagrams, annotations, crosswords, quizzes, questions and exhortations to ‘be
the table’ – doesn’t guarantee to do the trick when it isn’t allied to accuracy.
This is apparent in Head First SQL by Lynn Beighley (O’Reilly, 0-596-52684-9) where in the introduction we read: “but we assume that if you’re holding this book, you really want to learn about project management”. Er, no; that would be SQL, actually.
And it gets worse. On page 164 we find the gem: “SQL is known as a Relational Database Management System or RDBMS. Don’t bother memorising it. We only care about the word RELATIONAL”. The second sentence is entirely accurate but its juxtaposition with the first one is fabulously ironic.
Please don’t memorise the information because it is completely wrong. SQL certainly is not an RDBMS – SQL is a language and an RDBMS is an application. It’s rather like confusing petrol with an internal combustion engine: they work together but are two fundamentally different things.
A lack of understanding at this basic level destroys any confidence in the author’s authority. Teaming the author with a good technical proofreader could have made all the difference.
And then there’s the style. Head First SQL has, for my tastes, been a little too enthusiastic in its embrace of the “gosh, this stuff is so difficult to learn we’re going to show you a picture of a man looking perplexed” school of book writing.
Books with character certainly help the learning process. I have several favourites on my shelves, which have silly illustrations and captions (I thought I’d mention this in case I sound too stuffy…) This one won’t be joining them because it doesn’t feel idiosyncratic, it feels like formulaic funkiness.
Article tags
Related articles
Q.Why are some of the keys on my keyboard doing strange...
Q.Is my phone’s Bluetooth any use?
Q.Can I switch boot drives so that I can work on older...
St Helena, a 'small British village' in the mid-Atlantic, is seeking support and funding for a broadband connection
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |