Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7190711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:34:27+00:00 2026-05-28T19:34:27+00:00

First, if someone has a better title please help. If I have let’s say

  • 0

First, if someone has a better title please help.

If I have let’s say a ‘calendar’ table with a ‘day’ column. And I have the following query:

SELECT day, day AS testDay, testDay AS test2Day FROM calendar

MySQL will complain that “testDay” is an unknown column. Of course you will tell me that this statement is useless, but my statement looks more like this:

SELECT day, SOME_CRAZY_EXPRESSION_OF(day) AS testDay, EXPRESSION_OF(testDay) AS test2Day FROM calendar

And the point is I don’t want to evaluate twice the first expression to use it within the second expression.. So is there a way to use a value calculated in the select as part of the select itself?

Of course I could do:

SELECT day, SOME_CRAZY_EXPRESSION_OF(day) AS testDay, EXPRESSION_OF(SOME_CRAZY_EXPRESSION_OF(day)) AS test2Day FROM calendar

But I’m trying to avoid wasting. If I have no choice, that’s what I’ll do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:34:28+00:00Added an answer on May 28, 2026 at 7:34 pm

    In MySQL, you’ll want to assign a temporary variable to the value of the expression to be able to reuse it, this should do it;

    SELECT day, @tmp:=SOME_CRAZY_EXPRESSION_OF(day) AS testDay, 
        EXPRESSION_OF(@tmp) AS test2Day FROM calendar
    

    See this page for another example with more analysis on the performance impact.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, sorry for the title. Someone please propose a better one, I
First of all, if someone has a different, perhaps shorter (or better), solution to
Can someone please explain the following How was the first JDK release unit Tested?
I got great help in my first question n hopefully someone will tell me
I am writing my first FireFox extension and I have some questions. Maybe someone
I have a report with a dataset that has a column with booleans. In
First off, I have a better method of dealing with this issue so it's
Can someone explain to me why the following works for the first test but
Can someone explain this result to me. The first test succeeds but the second
Can someone explain the difference between these two, the first one is taken from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.