PostgreSQL String() Function: Display a couple of columns which contain a character 'C' in a specific column after 2nd position
12. Write a query to display the first name, last name for the employees, which contain a letter 'C' to their last name at 3rd or greater position.
Sample Solution:
Code:
SELECT first_name, last_name
FROM employees
WHERE POSITION('C' IN last_name) > 2;
Sample table: employees
Output:
pg_exercises=# SELECT first_name, last_name pg_exercises-# FROM employees pg_exercises-# WHERE POSITION('C' IN last_name) > 2; first_name | last_name ------------+----------- Samuel | McCain (1 row)
Practice Online
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query to display the first word in the job title if the job title contains more than one words.
Next: Write a query that displays the first name and the character length of the first name for all employees whose name starts with the letters 'A', 'J' or 'M'. Give each column an appropriate label. Sort the results by the employees' first names.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework