Search code examples
sqlpostgresqldateselectwhere-clause

How to answer this question : List employees who were hired in 1986


I am working on something and this my last thing I need to do. I have tried everything from

SELECT first_name, last_name, hire_date 
FROM employees
WHERE hire_date LIKE '1986%';

I keep getting this error message.

HINT: No operator matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 73

Please let me know what I am doing wrong

Thanks


Solution

  • That's normal because hire_date is certainly a DATE data type while the operator Like applies only for Strings data types. What you can do is extract the date directly: Where DATEPART(year, hire_date) = '1986'