Home > Software design >  SQL query: choosing only the first word in a column
SQL query: choosing only the first word in a column

Time:02-13

I am using PostgreSQL and Windows.

I have column data that looks like this:

column info

Table name: employees

I need to run an SQL query where the result will:

Display only FullName column.

Display ONLY THE FIRST WORD of each name in the column.

What would be the SQL query?

CodePudding user response:

There are all sorts of string functions described here String operators/functions. One that would work is:

select split_part('Adrian Klaver', ' ', 1);
 split_part 
------------
 Adrian

--So in your case
Select split_part("FullName", ' ', 1) from employees. 
  • Related