Query Specific Data in SQLite

SQLiteBeginner
Practice Now

Introduction

In this challenge, you'll leverage your SQL skills to query specific data within an SQLite database named treasure.db. The goal is to retrieve a hidden artifact by crafting a SELECT statement that filters results based on the artifact's id.

You'll connect to the database, write a query to select the name column from the artifacts table, and use a WHERE clause to identify the artifact with an id of 2.

Query Specific Data in SQLite

A valuable artifact is hidden in the database. Your mission is to retrieve it using your SQL skills.

Tasks

  • Write an SQL query to find the name of the artifact with the id equal to 2 from the artifacts table in the treasure.db database.

Requirements

  1. Connect to the SQLite database named treasure.db located in the ~/project directory using the sqlite3 command.
  2. Write a SELECT statement to retrieve the name column.
  3. Use a WHERE clause to filter the results based on the id column.
  4. The query must be executed within the sqlite3 shell.
  5. Save the output to a file named /home/labex/project/result.txt.

Examples

Executing the correct query should output:

cat /home/labex/project/result.txt
Placeholder

Hints

  • Remember to specify the database file path correctly.
✨ Check Solution and Practice

Summary

In this challenge, the task involves querying a specific artifact name from an SQLite database named treasure.db. The database contains a table named artifacts with columns id, name, and description. The goal is to retrieve the name of the artifact where the id is equal to 2.