BEGINNER SQL Track · 5 Lessons

SQL Beginner
Track

Learn to query SSURGO from scratch. No SQL experience required. Five lessons, each with live examples you run against the real SDA API.

Lessons Click any lesson to expand
01

The SSURGO Data Model

Understanding the tables before you query them

Beginner

SSURGO is organized as a hierarchy of four core tables. Understanding how they relate to each other is the most important thing you can learn before writing a single query.

legend (survey areas — the "where")
  └── mapunit (map units — polygon footprints)
        └── component (soil types within a map unit)
              └── chorizon (individual horizon layers)
The Golden Rule: Every SSURGO query follows this spine. Start at legend (pick your area), join to mapunit (what's on the map), join to component (what soil it is), then chorizon (layer by layer properties).

Key concepts

  • lkey — joins legend to mapunit
  • mukey — joins mapunit to component and muaggatt
  • cokey — joins component to chorizon and cointerp
  • areasymbol — like "WI025" = Dane County, Wisconsin
  • majcompflag — "Yes" = this is the dominant soil type
Try It — Explore Survey Areas
02

Your First Query

SELECT, FROM, TOP — returning map unit names

Beginner

The three most essential SQL keywords: SELECT (what columns), FROM (which table), TOP (how many rows). Every query you write will start here.

SELECT TOP 10   -- return only 10 rows
  column1,
  column2
FROM table_name
ORDER BY column1   -- sort results
Always use TOP: SSURGO has millions of rows. Always add TOP 10 or TOP 100 while exploring — otherwise you may get thousands of rows back.
Try It — Largest Map Units in SSURGO
03

Filtering with WHERE

Finding soils by state, survey area, or property

Beginner

WHERE narrows your results. The most powerful tool in soil queries is filtering by areasymbol to target a specific county, or by LIKE 'WI%' to match a whole state.

  • WHERE areasymbol = 'WI025' — exact county
  • WHERE areasymbol LIKE 'WI%' — all Wisconsin counties
  • WHERE muacres > 1000 — numeric comparison
  • WHERE drainagecl IN ('Well drained','Moderately well drained') — list match
Try It — Wisconsin Survey Areas
04

Sorting and Counting

ORDER BY, COUNT — summarizing your results

Beginner

Counting and sorting are the foundation of analysis. COUNT(*) tells you how many rows exist. GROUP BY groups them. ORDER BY DESC puts the biggest first.

GROUP BY rule: Every column in SELECT that isn't inside an aggregate function (COUNT, SUM, AVG) must appear in GROUP BY.
Try It — Map Unit Count by Survey Area (Iowa)
05

The Dominant Component

Every map unit has a dominant soil — here's how to find it

Beginner

A map unit contains multiple soil components — different soils that coexist within the same polygon. The dominant component is the one with the highest comppct_r (component percent). Use majcompflag = 'Yes' to filter to major components only.

Key columns in component: compname (soil series name), comppct_r (% coverage), drainagecl (drainage class), hydgrp (A/B/C/D runoff group), taxclname (full taxonomy).
Try It — Dominant Components (WI025, Dane County)
Congratulations! You've written a real SSURGO query joining three tables. This exact pattern — legend → mapunit → component with majcompflag — is the most common query in all of soil data science.
Up Next

Ready for Intermediate?

Add JOINs across all four tables, aggregate with GROUP BY, and calculate your first real soil property: Available Water Storage.

Intermediate Track → Open Query Lab