Ana Mar
Ana Mar

Reputation: 31

CREATE VIEW with concatenated fields

I have a table with Last Names, First Names, Hours and GPA's.

How do I create a view that displays a concatenated first name and last name, the StudentID and the GPA of the students who have passed at least 90 hours.

The concatenated names should be separated with one space. The three column headings should be FullName, StudentID and GPA. The rows should be sorted by last names, then first names.

Please help. I am lost as to how to approach this.

Upvotes: 1

Views: 15158

Answers (1)

C8H10N4O2
C8H10N4O2

Reputation: 19005

Use the operator || for concatenation (so you don't have to do nested CONCAT()).

Example:

create view v as 
    select (firstname || ' ' || lastname) "FullName", GPA, StudentId 
    from table
    where Hours>90
    order by lastname, firstname

Upvotes: 2

Related Questions