It is ten to five on a Thursday at a college admission office in Rajshahi. The principal calls: "Send me every CSE student from Dhaka with a CGPA above 3.5, best result first. I need it before the meeting." The student list is a spreadsheet of six thousand rows. You could filter it by hand, sort it, copy the right columns and pray you missed nobody. Or you could type one sentence to the database: SELECT name, cgpa FROM student WHERE dept = 'CSE' AND city = 'Dhaka' AND cgpa > 3.5 ORDER BY cgpa DESC; and have the answer in a second, the same right answer every time. That sentence is SQL, and this chapter teaches you to read and write it.
By the end of this chapter you will be able to build a table: sort any SQL command into its family, choose a data type for each column and write a complete CREATE TABLE. You will be able to look after what is in it: add, change and remove rows safely, say exactly how DELETE, TRUNCATE and DROP differ, save or undo your work with COMMIT and ROLLBACK, and give and take away permissions. And you will be able to ask it questions: SELECT queries that filter, sort, calculate and summarise, including the tricky cases where NULL changes the answer, and two written-paper favourites, finding duplicates and counting the years between two dates. The chapter has ten short parts. The first five build and change tables; the last five ask them questions. Every result printed here was produced by running the query in SQLite; where Oracle or MySQL behave differently we say so, and that part is taken from their manuals.