PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Why can't I still not use an ALIAS in the SELECT portion of an SQL statement?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Why can't I still not use an ALIAS in the SELECT portion of an SQL statement?

Réponse
 
LinkBack Outils de la discussion
Vieux 23/10/2007, 21h49   #1
Daevid Vincent
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Why can't I still not use an ALIAS in the SELECT portion of an SQL statement?

When will I be able to do something seemingly so basic as this re-use of an
alias?

SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
AS group_duration_date,
UNIX_TIMESTAMP(group_duration_date)
AS group_duration_date_timestamp
FROM end_user_groups;

Error Code : 1054
Unknown column 'group_duration_date' in 'field list'
(0 ms taken)

So instead I must do this very cumbersome and inefficient way:

SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
AS group_duration_date,
UNIX_TIMESTAMP(DATE_ADD('2007-10-23',
INTERVAL user_access_hours HOUR))
AS group_duration_date_timestamp
FROM end_user_groups;

*sigh*

This has been a cause of frustration since mysql 3.x series.
Are there any plans to fix this annoyance? If so, in what version?

Currently using:
mysql Ver 14.12 Distrib 5.0.41, for pc-linux-gnu (i686)

  Réponse avec citation
Vieux 24/10/2007, 01h39   #2
Peter Brawley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I still not use an ALIAS in the SELECT portion of anSQL statement?

>When will I be able to do something seemingly
>so basic as this re-use of an alias?


Do you know an implementation of SQL which allows this?

PB

Daevid Vincent wrote:
> When will I be able to do something seemingly so basic as this re-use of an
> alias?
>
> SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
> AS group_duration_date,
> UNIX_TIMESTAMP(group_duration_date)
> AS group_duration_date_timestamp
> FROM end_user_groups;
>
> Error Code : 1054
> Unknown column 'group_duration_date' in 'field list'
> (0 ms taken)
>
> So instead I must do this very cumbersome and inefficient way:
>
> SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
> AS group_duration_date,
> UNIX_TIMESTAMP(DATE_ADD('2007-10-23',
> INTERVAL user_access_hours HOUR))
> AS group_duration_date_timestamp
> FROM end_user_groups;
>
> *sigh*
>
> This has been a cause of frustration since mysql 3.x series.
> Are there any plans to fix this annoyance? If so, in what version?
>
> Currently using:
> mysql Ver 14.12 Distrib 5.0.41, for pc-linux-gnu (i686)
>
>
>

  Réponse avec citation
Vieux 24/10/2007, 02h26   #3
Daevid Vincent
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Why can't I still not use an ALIAS in the SELECT portion of an SQL statement?

Nope. I've only ever use mySQL. I only ever care to use mySQL. mySQL puts in
plenty of other features that no other RDBMS has or uses, and other RDBMS
have features that mySQL has, so what's the problem. Unless I was porting
to/from another RDBMS? It seems stupid that I can't do that though. I can
use the alias in the HAVING clause, and also in an ORDER BY clause. I'm not
saying it's a trivial change, I am saying that it would make a lot of sense
to do and I'm sure I'm not the first person to desire such a feature.

d

> -----Original Message-----
> From: Peter Brawley [mailto:peter.brawley@earthlink.net]
> Sent: Tuesday, October 23, 2007 5:39 PM
> To: Daevid Vincent
> Cc: mysql@lists.mysql.com
> Subject: Re: Why can't I still not use an ALIAS in the SELECT
> portion of an SQL statement?
>
> >When will I be able to do something seemingly
> >so basic as this re-use of an alias?

>
> Do you know an implementation of SQL which allows this?
>
> PB
>
> Daevid Vincent wrote:
> > When will I be able to do something seemingly so basic as

> this re-use of an
> > alias?
> >
> > SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
> > AS group_duration_date,
> > UNIX_TIMESTAMP(group_duration_date)
> > AS group_duration_date_timestamp
> > FROM end_user_groups;
> >
> > Error Code : 1054
> > Unknown column 'group_duration_date' in 'field list'
> > (0 ms taken)
> >
> > So instead I must do this very cumbersome and inefficient way:
> >
> > SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
> > AS group_duration_date,
> > UNIX_TIMESTAMP(DATE_ADD('2007-10-23',
> > INTERVAL

> user_access_hours HOUR))
> > AS group_duration_date_timestamp
> > FROM end_user_groups;
> >
> > *sigh*
> >
> > This has been a cause of frustration since mysql 3.x series.
> > Are there any plans to fix this annoyance? If so, in what version?
> >
> > Currently using:
> > mysql Ver 14.12 Distrib 5.0.41, for pc-linux-gnu (i686)
> >
> >
> >

>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=daevid@daevid.com
>
>


  Réponse avec citation
Vieux 24/10/2007, 04h46   #4
mysql@subtropolix.org
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I still not use an ALIAS in the SELECT portion of anSQL statement?

Daevid Vincent wrote:
> Nope. I've only ever use mySQL. I only ever care to use mySQL. mySQL puts in
> plenty of other features that no other RDBMS has or uses, and other RDBMS
> have features that mySQL has, so what's the problem. Unless I was porting
> to/from another RDBMS?


This strikes me as a *terrible* reason.

It seems stupid that I can't do that though. I can
> use the alias in the HAVING clause, and also in an ORDER BY clause.


Yes, but those are HAVING and ORDER BY clauses. You recognise that they
are distinct parts of a SELECT statement, so ...

I'm not saying it's a trivial change

So far, i'd say that you're suggesting it is.

http://dev.mysql.com/tech-resources/...sql-views.html

brian
  Réponse avec citation
Vieux 24/10/2007, 05h38   #5
mysql@subtropolix.org
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I still not use an ALIAS in the SELECT portion of anSQL statement?

mysql@subtropolix.org wrote:
> Daevid Vincent wrote:
>
>> Nope. I've only ever use mySQL. I only ever care to use mySQL. mySQL
>> puts in
>> plenty of other features that no other RDBMS has or uses, and other RDBMS
>> have features that mySQL has, so what's the problem. Unless I was porting
>> to/from another RDBMS?

>
>
> This strikes me as a *terrible* reason.
>
> It seems stupid that I can't do that though. I can
>
>> use the alias in the HAVING clause, and also in an ORDER BY clause.

>
>
> Yes, but those are HAVING and ORDER BY clauses. You recognise that they
> are distinct parts of a SELECT statement, so ...
>
> I'm not saying it's a trivial change
>
> So far, i'd say that you're suggesting it is.
>
> http://dev.mysql.com/tech-resources/...sql-views.html
>
> brian
>


I've looked for--but cannot find--a page online that explains this
nicely. Suffice to say that the problem is similar to that of trying to
use a column alias in the WHERE clause. In that case, it's because WHERE
is parsed before the SELECT clause. In your case, it's simply that the
column expressions are constructed more or less as one, not from left to
right or anything like that.

You could also use a derived table here, i should think:

SELECT foo.bar, UNIX_TIMESTAMP(foo.bar) FROM (
SELECT DATE_ADD('2007-10-23', INTERVAL user_access_hours HOUR)
AS bar
FROM end_user_groups
) AS foo;

brian
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16084 seconds with 13 queries