Introduction
In this challenge, you'll assist the HR department by extracting a list of Marketing employees from a PostgreSQL database. You'll need to write a SQL query to select the id and name of employees in the 'Marketing' department, and save the query results to a file for verification.
The database and sample data will be automatically prepared for you. You'll need to use sudo -u postgres psql to connect to the database and execute your query. The query results should be saved to a specified file that will be used to verify your solution.
Find Marketing Employees in PostgreSQL
The HR department needs a list of all employees in the Marketing department for a team-building event. Can you help them extract this information from the employee database?
Tasks
- Connect to PostgreSQL using
sudo -u postgres psql - Write and execute a SQL query to select the
idandnameof all employees whose department is 'Marketing' - Save the query results to
~/project/marketing_employees.txt
Requirements
- Use
sudo -u postgres psqlto connect to the database - Write a SQL query to select the
idandnamecolumns from theemployeestable where thedepartmentis 'Marketing' - Save the complete query output (including column headers and row count) to
~/project/marketing_employees.txt
Examples
After executing your query in psql, the output should look like this:
id | name
----+---------------
* | XXX XXX
* | XXX XXX
(2 rows)
Save this exact output to the marketing_employees.txt file.
Hints
- The database and sample data are already prepared for you
- Use the
WHEREclause to filter results based on thedepartmentcolumn - To save query results to a file, you can copy and paste the output from psql
- Make sure to include the column headers and row count in the saved output
Summary
In this challenge, you learned how to:
- Connect to a PostgreSQL database using
sudo -u postgres psql - Write a SQL query to filter data based on specific conditions
- Extract employee information from a database table
- Save query results to a file for verification
The task demonstrated practical database querying skills and the importance of proper output formatting when saving results for verification. These skills are essential for data extraction and reporting in real-world database management scenarios.


