SmartQueryTools

Sample CSV Files Online

Sample rows from CSV files — first N, last N, or random — directly in your browser.

How to sample CSV files

  1. Drop your file onto the upload area. It is loaded into the in-browser engine and the first 200 rows are shown.
  2. Pick a Method: First takes rows from the top, Last takes rows from the bottom, and Random picks rows from anywhere in the file.
  3. Enter the Number of rows you want. The default is 100.
  4. Click Sample. The preview shows the sampled rows and how many were taken.
  5. Click Download to save the sample in the same format you uploaded.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Worked example

A facilities team logs a cold-room temperature every two hours and only needs the latest three readings to check a door alarm.

Input (CSV)

reading_at,sensor,temp_c
2026-08-01 00:00:00,cold-room-2,3.8
2026-08-01 02:00:00,cold-room-2,3.9
2026-08-01 04:00:00,cold-room-2,4.1
2026-08-01 06:00:00,cold-room-2,6.7
2026-08-01 08:00:00,cold-room-2,7.2
2026-08-01 10:00:00,cold-room-2,4

Settings

  • Method: Last
  • Number of rows: 3

Result

reading_atsensortemp_c
2026-08-01 06:00:00cold-room-26.7
2026-08-01 08:00:00cold-room-27.2
2026-08-01 10:00:00cold-room-24

Last takes rows by their position in the file, not by the timestamp value. The file has six rows, so asking for three returns rows 4 to 6 in their original order. If the log were not already in time order, sort by reading_at first. Random with the same settings would return three rows from anywhere in the file.

Working with CSV files

A CSV sample is a quick way to share a representative slice of a large export, or to test an import script before running the full file. First and Last follow the row order in the file as written. Random draws rows from the whole file, so a sample of 500 from a year of transactions is spread across the whole year, not bunched in January. First with a small N is the quickest check that the header and delimiter were detected correctly.

The sample keeps the full header and every column. Types are detected from the whole file before sampling, and the sample is written back as text, so a column detected as numeric in the source is not re-guessed from only the sampled rows. Fields containing commas, quotes or line breaks are quoted, and blank cells stay blank. The source file is never changed, so you can draw as many samples as you like.

Frequently Asked Questions

Does the random CSV sample include the header?

Yes. The header is not counted as a row. The downloaded file has the header plus the number of data rows you asked for.

Why is my random CSV sample different every time?

Each run draws a fresh random selection. For a repeatable sample, use the SQL Query tool with USING SAMPLE reservoir(500 ROWS) REPEATABLE (42), with any fixed number as the seed.

What happens if I ask for more rows than the file has?

You get every row. First and Last return the whole file, and Random returns all rows as well.

Is the random sample the same each time?

No. Every click of Sample draws a new random set, and the rows may not keep their file order. For a repeatable sample, use the SQL Query tool with USING SAMPLE reservoir(N ROWS) REPEATABLE (seed).

What is the difference between Sample and Head or Tail?

First and Last in this tool do the same as Head and Tail. Sample adds the Random method, which spreads the selection across the whole file.

Related Tools