Introduction
In this challenge, you'll be working with an SQLite database named employees.db to filter employee data. The goal is to query the database and extract the names of all employees belonging to the IT department.
You'll need to connect to the database using the sqlite3 command, write a SELECT statement with a WHERE clause to filter by department, and then manually copy the output of your query and save it to a file named result.txt in the /home/labex/project/ directory. The result.txt file should contain a list of IT department employee names, one name per line.
Filter SQLite Data for IT Department
This challenge tests your ability to query specific data from an SQLite database, focusing on filtering employees by department.
Tasks
- Write an SQL query to select the names of all employees in the IT department from the
stafftable. - Copy the output of your query and save it to a file named
result.txtin the/home/labex/project/directory.
Requirements
- Connect to the SQLite database named
employees.dblocated in the/home/labex/project/directory using thesqlite3command. - Write a
SELECTstatement to retrieve thenamecolumn. - Use a
WHEREclause to filter the results based on thedepartmentcolumn. - Execute the query, copy the results, and save them to
/home/labex/project/result.txtusing a text editor or theechocommand. - Your SQL query should be placed directly in the
sqlite3shell, without creating any additional SQL files.
Examples
Executing the correct query and saving the output should result in a result.txt file with the following content:
Bob
David
Frank
Hints
Remember to specify the database file path correctly.
You can copy the output from the terminal and use
nanoor another text editor to save it toresult.txt.Alternatively, you can use the
echocommand with appropriate redirection to save the output:echo -e "XXX" > /home/labex/project/result.txtEnsure that your
WHEREclause accurately filters for the IT department.
Summary
In this challenge, the goal is to query an SQLite database named employees.db to retrieve the names of all employees belonging to the IT department. This involves connecting to the database using the sqlite3 command, writing a SELECT statement to retrieve the name column, and using a WHERE clause to filter the results based on the department column.
The key learning points include constructing an accurate WHERE clause to filter data based on a specific department value, and then manually copying and saving the query results to a specified file. The setup involves installing SQLite and creating the database and table with sample data.


