Reading from a Table
-
Prerequisite
Description
Reading from a table is similar to reading from a list, except that you need to specify the column names and row numbers. We will use the table “t1” in our examples below. It has 4 columns and 3 rows.
Get the number of rows in a table
You can use the “row count” block to get the number of rows in a table. If the table is empty, then this block will report 0.
Reading the Value of One Item
If you already know the column name and row number of an item you are interested in, you can use this block to read its value.
Parameters
- Row Number: The row number has to be between 1 and the total number of rows in the table.
- Column Name: The column name is not case-sensitive. For example, you can use “Name” or “name” to refer to the “NAME” column.
Demo
Reading an Entire Row
Sometimes you may want to read the values of all items in a row. You can use this block to get all the values joined together.
Parameters
- Row Number: The row number has to be between 1 and the total number of rows in the table.
- Table Name: Select the name of the table from the dropdown.
- Separator: Which symbol to separate between the values of different columns in this row.
Demo
Looking for an Item in a Column
You can search for an item in any column of a table using this block:
Parameters
- Item to look for: The exact text of the item you are looking for.
- Column Name: The column that you want to search.
- Table Name: Select the name of the table from the dropdown.
Demo
For example, we can look for the name of any student in the “Name” column, and this block will return the row number. If that item is not found, then this block will return -1.
Looking for an Item that contains a value in a Column
Sometimes you do not want an exact match. For example, you only know part of an item, but not the exact value of that item. You can look for any item that contains a value with this block:
Parameters
- Part of item to look for: The part of the item you are looking for.
- Column Name: The column that you want to search.
- Table Name: Select the name of the table from the dropdown.
Demo
For example, suppose we know a student’s first name is “Aiden”, but we do not know his full name. We can look for any student whose name contains “Aiden”. This block will return the row number. If no name contains “Aiden”, then this block will return -1.
Looking Up in One Column Using Another Column
Sometimes you may want to look up a table using another column. For example, you might want to know the height of the student with an ID of 101. To answer that question, you use this block:
Parameters
- Target Column: The column you want to query about, such as “height” in our example.
- Table Name: Select the name of the table from the dropdown.
- Lookup Column: The column that you want to look up with, such as “ID” in our example.
- Item in Lookup Column: The value you are searching for in the lookup column, such as 101 in our example.
Demo
-