Get startedGet started for free

Connecting with files

1. Connecting with files

Welcome to this short course on using SQL in DataLab.

2. Instructor & DataLab enthusiast

My name is Jasmin, and I'll be your guide. I use DataLab daily for my work and personal projects, including some on DataCamp.

3. Our learning journey

This course follows the introductory course, which covered various cell types, including Explore and Chart cells, AI features, and accessing data and files. If that's new to you, I recommend a refresher before continuing. We'll focus on using SQL in DataLab workbooks, building on what you saw in the intro course.

4. Environments

As a reminder, SQL cells are available in the Python and R language environments on DataLab. We'll use the SQL cells in the Python environment, but the same will apply to R.

5. Connecting files on DataLab

Before writing queries, we'll set up some data. In DataLab, we can opt to only connect a file; there's no need for installations or databases. If you prefer to do that, take a look at this linked documentation for more details. There are several options for setting up data for SQL; we'll focus on two approaches: Google Sheets and CSV files.

6. Connecting a data source

To set up a Google Sheet, we use the built-in connector, select the Google Sheets option and follow the instructions to sign in. Once signed in,

7. Connecting a data source

we select the sheet we want to connect. This connection allows read-only access. Once connected, the Google Sheet will appear as an icon. We can select it to complete the connection, which we can see is completed when a SQL cell and corresponding output are automatically generated.

8. Querying a Google Sheet

Perfect! We can now query this Google Sheet with SQL! We'll need to use the sheet name, not the file name, in the FROM clause. Unlike standard SQL tables, we must enclose the sheet name in quotation marks. These are automatically added in the sample query generated when we first connect a file.

9. Connecting a CSV file

Let's now look at adding a CSV file. In a brand new workbook, there is the option to drag and drop our files on the first page without navigating to the files area.

10. Connecting a CSV file

Alternatively, we can navigate to our workbook files and upload our CSV file to achieve the same result.

11. Querying a CSV file

Similar to Google Sheets, the generated query will include quotation marks in the FROM clause. However, these aren't required for querying a CSV file. We do need to include the file extension though, .csv, here.

12. Explore cells

You learned about Explore cells in the introductory course. Explore cells let us quickly preview our data. It's an excellent way to understand our data's structure and identify what columns and aggregations we'd be interested in. Here we use the explore features in the cell generated after connecting the file.

13. Let's practice!

Great work; let's review these connections before we start querying.