Simple clear advice in plain English

Hands on: SQL conditions and operators

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

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Hands on: Database normalisation

A discussion about database normalisation and your preferred version of Microsoft Access

Hands on: Using SQL sub-queries

Fine-tune your database queries, choose your Access version, and code maps

Hands on: Delete and Append action queries for your database

Delete and Append queries explained

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Samsung RV520-A07

£359.98- Buy it now

img

Acer Aspire 5750G (LX.RXP02.019)

£399.99- Buy it now

img

Apple MacBook Pro (MD313B/A)

£904.37- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Virtual drive

A set of files seen by Windows as a separate hard disk.

Great shopping deals from Computeractive