I have a database with first names and last names.
I select some of them, not all.
I want to show the last name with one exception, when the last name is the same for two people in the current selection, prepend the initial of the first name followed by full-stop space. (G.)
The app is running on a mobile device so I’m worried that looping through data and comparing each name with all the other names (for inside for) is too resource costly.
Is it possible to check this in the query and do a case statement where I concatenate substr of first name with .?
How should I do this?
Thank you.
The following SQL queries show how to do achieve this.
It would be helpful to have an index on the lastname column so that the sub-query is more efficient.