Step 3: Query the tables in a ledger - Amazon Quantum Ledger Database (Amazon QLDB)

Step 3: Query the tables in a ledger

After creating tables in an Amazon QLDB ledger and loading them with data, you can run queries to review the vehicle registration data that you just inserted. QLDB uses PartiQL as its query language and Amazon Ion as its document-oriented data model.

PartiQL is an open source, SQL-compatible query language that has been extended to work with Ion. With PartiQL, you can insert, query, and manage your data with familiar SQL operators. Amazon Ion is a superset of JSON. Ion is an open source, document-based data format that gives you the flexibility of storing and processing structured, semistructured, and nested data.

In this step, you use SELECT statements to read data from the tables in the vehicle-registration ledger.


When you run a query in QLDB without an indexed lookup, it invokes a full table scan. PartiQL is SQL compatible, so it supports such queries. However, do not run table scans for production use cases in QLDB, as they can cause performance problems on large tables, including transaction timeouts.

To avoid table scans, you must run statements with a WHERE predicate clause using an equality operator on an indexed field or a document ID; for example, WHERE indexedField = 123 or WHERE indexedField IN (456, 789). For more information, see Optimizing query performance in the Working with data and history topic.

To query the tables

  1. Open the Amazon QLDB console at

  2. In the navigation pane, choose Query editor.

  3. Choose the vehicle-registration ledger.

  4. In the query editor window, enter the following statement to query the Vehicle table for a particular vehicle identification number (VIN) that you added to the ledger, and then choose Run.

    To run the statement, you can also use the keyboard shortcut Ctrl+Enter for Windows, or Cmd+Return for macOS. For more keyboard shortcuts, see Accessing Amazon QLDB using the console.

    SELECT * FROM Vehicle AS v WHERE v.VIN = '1N4AL11D75C109151'
  5. You can write inner join queries. This query example joins Vehicle with VehicleRegistration and returns registration information along with attributes of the registered vehicle for a specified VIN.

    Enter the following statement, and then choose Run.

    SELECT v.VIN, r.LicensePlateNumber, r.State, r.City, r.Owners FROM Vehicle AS v, VehicleRegistration AS r WHERE v.VIN = '1N4AL11D75C109151' AND v.VIN = r.VIN

    You can also join the Person and DriversLicense tables to see attributes related to the drivers who were added to the ledger.

    Repeat this step for the following.

    SELECT * FROM Person AS p, DriversLicense AS l WHERE p.GovId = l.LicenseNumber

To learn about modifying documents in the tables in the vehicle-registration ledger, see Step 4: Modify documents in a ledger.