How to select only the people with the first name [closed]

-4

I would like to know how to select people who have only the first name, that is, they do not have a last name.

Example:

Nome
----------
Leonardo Roberto
Ana
Júlio
Maria Ana

Expected result:

  

Ana, Júlio

    
asked by anonymous 06.12.2018 / 11:26

2 answers

2

Although your question is unclear, I think it will be simple to come up with a solution.
Let's assume you have the table below (very basic example):

CREATE TABLE Pessoas
(
    Nome VARCHAR(255)
)

Table containing the following information:

INSERT INTO Pessoas VALUES('Leonardo Roberto')
INSERT INTO Pessoas VALUES('Ana')
INSERT INTO Pessoas VALUES('Júlio')
INSERT INTO Pessoas VALUES('Maria Ana')

To get names that do not have a last name, just look for those that do not have spaces:

SELECT  * 
FROM    Pessoas
WHERE   STRPOS(LTRIM(RTRIM(Nome)), ' ') = 0
    
06.12.2018 / 11:45
0

An alternative would be to call the POSITION() function; whereas the surname name will always be separated by a space ( ), you can use the following:

SELECT *
FROM pessoa
WHERE POSITION(' ' in nome) > 0;
    
06.12.2018 / 12:43