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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:59:04+00:00 2026-05-11T18:59:04+00:00

The query I’m running is as follows, however I’m getting this error: #1054 –

  • 0

The query I’m running is as follows, however I’m getting this error:

#1054 – Unknown column ‘guaranteed_postcode’ in ‘IN/ALL/ANY subquery’

SELECT `users`.`first_name`, `users`.`last_name`, `users`.`email`,
SUBSTRING(`locations`.`raw`,-6,4) AS `guaranteed_postcode`
FROM `users` LEFT OUTER JOIN `locations`
ON `users`.`id` = `locations`.`user_id`
WHERE `guaranteed_postcode` NOT IN #this is where the fake col is being used
(
 SELECT `postcode` FROM `postcodes` WHERE `region` IN
 (
  'australia'
 )
)

My question is: why am I unable to use a fake column in the where clause of the same DB query?

  • 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-11T18:59:05+00:00Added an answer on May 11, 2026 at 6:59 pm

    You can only use column aliases in GROUP BY, ORDER BY, or HAVING clauses.

    Standard SQL doesn’t allow you to
    refer to a column alias in a WHERE
    clause. This restriction is imposed
    because when the WHERE code is
    executed, the column value may not yet
    be determined.

    Copied from MySQL documentation

    As pointed in the comments, using HAVING instead may do the work. Make sure to give a read at this question too: WHERE vs HAVING.

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

Sidebar

Related Questions

query 1 : this will count all the record with email 'emali@test.com' select count(*)
This query is supposed to be dropping temp tables/views from a sql DB however
Query gives me some error: Msg 156, Level 15, State 1, Line 4 Incorrect
Query was this: CREATE TABLE `query` ( `id` int(11) NOT NULL auto_increment, `searchquery` varchar(255)
Query's throwing an ORA-00907 Error when I try to paste a list of values
Query to find All bars that sell three different beers at the same price?
Query : List the film title and the leading actor for all of 'Julie
Query to get total commissions for an employee, and update their totalCommission column in
query = Files .Where(file => file.Fileinfo.Name.ToUpper().Contains(textBox1.Text.ToUpper())) .Take(7).ToList(); I hate asking this question, but I
My query is this... SELECT a.ID, a.time, a.quote, a.quantity, a.media, a.print, a.pack FROM quotes

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.