472,126 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

column alias on mass

sks
Hi all,

Is possible to retrieve all columns and alias them all at once. Eg, normally
you would write

select * from products which would return

id | name | price
-----------------------
1 | Test | 14.00

but I want to be able to say

select p.* from products p, so that it returns the columns as such

p.id | p.name | p.price

Obviously I can do this manually as such

select p.id, p.name, p.price from products p ....

But that would take a lot of big queries as some of my tables have 50
columns.
May 2 '06 #1
2 3398
sks wrote:
but I want to be able to say

select p.* from products p, so that it returns the columns as such

p.id | p.name | p.price

Obviously I can do this manually as such

select p.id, p.name, p.price from products p ....


Actually, that would return

id | name | price

The column labels don't implicitly include the table alias dot notation.
You'd have to do a query like this:

select p.id as `p.id`, p.name as `p.name`, p.price as `p.price` from
products p ....

It's good to get in the habit of using the backquotes, because then you
can use special characters or even whitespace in your column labels.

There is no syntax to declare the column labels automatically. You have
to specify all of them individually.

Regards,
Bill K.
May 2 '06 #2
sks

"Bill Karwin" <bi**@karwin.com> wrote in message
news:e3*********@enews4.newsguy.com...
sks wrote:
but I want to be able to say

select p.* from products p, so that it returns the columns as such

p.id | p.name | p.price

Obviously I can do this manually as such

select p.id, p.name, p.price from products p ....


Actually, that would return

id | name | price

The column labels don't implicitly include the table alias dot notation.
You'd have to do a query like this:

select p.id as `p.id`, p.name as `p.name`, p.price as `p.price` from
products p ....

It's good to get in the habit of using the backquotes, because then you
can use special characters or even whitespace in your column labels.

There is no syntax to declare the column labels automatically. You have
to specify all of them individually.


Ok thanks for replying.
May 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Gord | last post: by
2 posts views Thread by muzamil | last post: by
2 posts views Thread by Stefan Leitich | last post: by
1 post views Thread by Plamen Ratchev | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.