Helix Systems' facilities team is updating the New York office directory ahead of a building security review.
Write a query to return the name and location of every department based in New York.
Assumptions:
- The
departmentstable contains every department at Helix Systems. - The
locationcolumn records the office city for each department; New York departments havelocationset to'New York'.
Output:
- One row per New York department, with columns
nameandlocation.
Schema · hr 4 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
location
FROM
departments
WHERE
location = 'New York' The shape
An equality check on location narrows the directory to a single office. The two-word value goes inside single quotes as a string literal, spaces included.
Clause by clause
SELECT name, locationreturns the two columns the facilities team needs to confirm which department is which and that they are all reading from the same office. Thelocationcolumn travels through the filter and lands in the output — referencing a column inWHEREdoesn't disqualify it fromSELECT.FROM departmentsis the source — every department at Helix Systems.WHERE location = 'New York'keeps only the rows whoselocationvalue is exactly the string'New York'. The space between the two words is part of the literal; the quotes wrap the entire value as one string.
The trap
String equality in PostgreSQL is byte-for-byte. 'New York' does not match 'new york', 'NEW YORK', 'New York' with two spaces, or 'New York ' with a trailing space. When real data has been entered by hand over time, the same city can show up under several spellings, and an exact-match filter quietly leaves the variants out of the result.
You practiced an equality filter on a string column. String-equality filters are case-sensitive — 'New York' only matches rows with that exact value, not 'NEW YORK' or 'new york'.