Find Marketing Employees in PostgreSQL

PostgreSQLBeginner
Practice Now

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

  1. Connect to PostgreSQL using sudo -u postgres psql
  2. Write and execute a SQL query to select the id and name of all employees whose department is 'Marketing'
  3. Save the query results to ~/project/marketing_employees.txt

Requirements

  1. Use sudo -u postgres psql to connect to the database
  2. Write a SQL query to select the id and name columns from the employees table where the department is 'Marketing'
  3. 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 WHERE clause to filter results based on the department column
  • 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.

✨ Check Solution and Practice