SQL Column Selection & Design.
Columns in the SELECT LIST.
How to change Column Names in the SELECT statement.
- You can select all columns in a table with the * character.
- Choose selected columns specified by a comma in between.
- SQL lets you add to and manipulate field name in return to make them easier to read.
-
You have to use apostrophe around the new column name only if
the name contain one or more space-characters.
Example:MySQL, Oracle, SQL server, PostgreSQL:
select First_name as "First Name", Last_name as "Last Name" from customers
You could do the same without the AS word as it is optional.MySQL, Oracle, SQL server, PostgreSQL:select First_name "First Name", Last_name "Last Name" from customers
What ever the result should be:First Name Last Name Ricard Nixon Robert Redford Judith Bowman Sandra Emerson Marcy Darnovsky
How to use Character Strings in the Query Results.
- Use '(single quotes) to specify a string and the keyword as for a header name in "(double quotes). Some RDBMS will misunderstand if you do not use the keyword as in this case.
- Some DBMS also handles text and/or header surrounded with only '(single quotes) or "(double quotes).
- If you need a "(double quotes) inside a "(double quotes) surrounded string you need to provide this in front with two double quotes (""). Oracle can not handle this.
-
If you need a '(single quotes) inside a '(single quotes) surrounded string you need to
provide this in front with two single quotes ('').
Example:MySQL, Oracle, SQL server, PostgreSQL:
SELECT 'The Customer''s name is ' AS "Information", first_name AS "First Name", last_name AS "Last Name" FROM customers;
The result should be:Information First Name Last Name The Customer's name is Ricard Nixon The Customer's name is Robert Redford The Customer's name is Judith Bowman The Customer's name is Sandra Emerson The Customer's name is Marcy Darnovsky
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.