Displaying the content of a TABLE
Displaying the content of a TABLE in SQL
In this very simple example we will see how to display the content of a table. Since we are working in the notebook, we will load the sql extension in order to manipulate the database. The database mydatabase.db is a SQLite database already created before the example.
#load the extension
%load_ext sql
#connect to the database
%sql sqlite:///mydatabase.db
'Connected: @mydatabase.db'
In order to extract all the values from a table, we will use the following command : SELECT * FROM TABLE In our example, we want to display the data contained in the table named tutyfrutty
%sql SELECT * FROM tutyfrutty
* sqlite:///mydatabase.db
Done.
| index | fruit | color | kcal |
|---|---|---|---|
| 0 | Banana | yellow | 89 |
| 1 | Orange | orange | 47 |
| 2 | Apple | red | 52 |
| 3 | lemon | yellow | 15 |
| 4 | lime | green | 30 |
| 5 | plum | purple | 28 |
| 7 | Cranberry | red | 308 |