Page 1 of 1
Combining Fields in Query
Posted: Mon Oct 20, 2003 9:02 am
by AliasBDI
Not sure how to do this... if someone can help me.
I have a query that looks for a record which has "firstname" and "lastname" fields. I want it to take those two fields and combine them under a new variable name called "fullname". How would this look?
Posted: Mon Oct 20, 2003 10:17 am
by Kriek
A SELECT expression may be given an alias using AS.
Code: Select all
SELECT firstname, lastname AS fullname FROM table ORDER BY fullname;
Well here it is...
Posted: Mon Oct 20, 2003 10:38 am
by AliasBDI
Kriek-
I tried that but it did not work. I think it reads the "firstname" as a field and then "lastname" as a field with a new variable name, which is "fullname".
Nevertheless, I was able to pull it off with the CONCAT.
Code: Select all
SELECT CONCAT("firstname", " ", "lastname") AS fullname FROM table
It displayed the firstname (John) and the lastname (Doe) as the fullname (John Doe).
Superb!
Posted: Mon Oct 20, 2003 11:03 am
by microthick
I think it's something like:
SELECT FirstName + ' ' + LastName as WholeName FROM ...
Posted: Mon Oct 20, 2003 11:33 am
by Kriek
Alias, I did not mention the CONCAT() function, because you did not specify whether or not you wanted to retain the previous fields as values. At any rate, it works now; glad I could be of assistance to you.