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 7644321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:39:34+00:00 2026-05-31T09:39:34+00:00

Problem I am using alternate column name (alias) in a Query, I can use

  • 0

Problem

I am using alternate column name (alias) in a Query, I can use the alias "given_name" as part of the ORDER BY but am unable to use it as part of the WHERE clause. The WHERE "given_name" is passed in as the result of a request out of my control and I do not know the actual column name that should be used in the WHERE condition.

Question

  1. It there a way/hack to use a column alias in a WHERE clause?
  2. Is there a way to find the column name from an alias?

Research

After some research it looks like alias are added after after the WHERE clause.

Example

SELECT profile.id AS id, given.name AS 'given_name', family.name AS 'family_name'
FROM green_profile profile 
LEFT JOIN green_name given ON given.profileid = profile.id AND given.name_typeid = 0 
LEFT JOIN green_name family ON family.profileid = profile.id AND family.name_typeid = 1 
WHERE given_name LIKE 'levi%' 
ORDER BY given_name DESC LIMIT 0 , 25
  • 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-31T09:39:35+00:00Added an answer on May 31, 2026 at 9:39 am

    Untested, but this hack should work…

    SELECT * FROM (  
        SELECT profile.id AS id, given.name AS 'given_name', family.name AS 'family_name'
        FROM green_profile profile 
        LEFT JOIN green_name given ON given.profileid = profile.id AND given.name_typeid = 0 
        LEFT JOIN green_name family ON family.profileid = profile.id AND family.name_typeid = 1   
    ) as temptable
    WHERE given_name LIKE 'levi%' 
    ORDER BY given_name DESC LIMIT 0 , 25
    

    It works by simply creating a temporary table from your original select statement (without the where clause and ordering), which has the column names you specify. You then select from this with the column names you want.

    A better approach might be to create a view, with the column names you want, and select from the view…

    CREATE VIEW newtable AS
    SELECT profile.id AS id, given.name AS 'given_name', family.name AS 'family_name'
    FROM green_profile profile 
    LEFT JOIN green_name given ON given.profileid = profile.id AND given.name_typeid = 0 
    LEFT JOIN green_name family ON family.profileid = profile.id AND family.name_typeid = 1;
    

    And then…

    SELECT * FROM newtable
    WHERE given_name LIKE 'levi%' 
    ORDER BY given_name DESC LIMIT 0 , 25
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can the following problem be dealt with? We're using lazy loaded NHibernate properties
I have been trying to get it to work using this thread but can't
The problem: Using ASp.NET MVC for reporting. Given: 1. A report that is tabular
I have a problem using the Java search function in Eclipse on a particular
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem using template instantiation [*]. file foo.h class Foo {
I am having a problem using the Unity Application Block, I have created a
I'm having a problem using CSS's display:inline property with the list-style-image: property on <li>
I have a problem using Linq to NHibernate to load an object and eagerly

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.