AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Sorting into order

Week 5 · Unit 2: Be a data controller · 3 lessons
2

Sort whole rows

Computing 4: Unit 2, pp. 20–33
GoalSort a table by one column and keep each row together.
New words
column · a line of cells going down; it holds one fieldrow · a line of cells going across; it holds one recordsort by · to put the rows in order using the data in one column
Explanation

A table has rows and columns. Each row is a record: all the facts about one thing. When we sort a table, we choose one column to sort by. The rows move so that this column is in order, but each row stays together. If only one column moved, the names would be joined to the wrong ages! So we always select the whole table, including the headings, before we sort. The chosen column can be sorted in ascending or in descending order. Sorting can answer questions such as “Who is the youngest?” or “Which book has the most pages?”

AB
1NameAge
2Ana7
3Leo9
4Omar10
5Yuki8
6Ben6
Worked examples
AB
1NameAge
2Ben6
3Ana7
4Yuki8
5Leo9
6Omar10
Here is the table sorted by Age in ascending order. Ben is the youngest and is at the top. Omar is the oldest and is at the bottom. Each name moved with its age.
AB
1NameAge
2Yuki8
3Omar10
4Leo9
5Ben6
6Ana7
Now the same table is sorted by Name from Z to A (descending). The names come in the order Yuki, Omar, Leo, Ben, Ana, and every age moved with its name.
AB
1NameAge
2Ana6
3Leo7
4Omar8
5Yuki9
6Ben10
A mistake: someone sorted only the Age column. The names stayed where they were, so the table now says that Ana is 6, but Ana is really 7. This is why the whole table must be selected.
Class activity

Card table (with a friend): write five book cards, each with a title and a number of pages: Kite Day 96, Sea Stories 120, Big Map Book 200, Tiny Ants 32, Moon Trip 64. Sort the cards by pages in ascending order and write the titles down. Now sort the cards by title from A to Z and write them down again. Which book is the longest? Which comes first in the A to Z list?

Practice
1
Write the rows in ascending order by Price.
AB
1ToyPrice
2Top4
3Kite6
4Drum9
5Ball3
2
Write the same rows sorted by Toy from A to Z.
3
Why must we select the headings and all the columns before sorting?
4
Which column is this table sorted by, and in which order?
AB
1PlayerScore
2Yuki9
3Ana8
4Leo6