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
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
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
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;