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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:44:13+00:00 2026-05-31T16:44:13+00:00

Gonna give an example since it’s hard to understand what i’m talking about: SELECT

  • 0

Gonna give an example since it’s hard to understand what i’m talking about:

   SELECT a.f1, 
          b.f1, 
          IF(a.f3 <> '', a.f3, b.f3) as f3 
     FROM a 
LEFT JOIN b 
       ON b.f4 = a.f4 
    WHERE f3 = 'something'

Now, this won’t work because i can’t have an alias as a field in the where clause, so how can I apply the condition to that f3 field that’s either from a or b. Preferably without putting a bunch of IFs in the where clause

  • 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-31T16:44:15+00:00Added an answer on May 31, 2026 at 4:44 pm

    Try this:

    SELECT * FROM (
        SELECT a.f1, b.f1,
          IF(a.f3 <> '', a.f3, b.f3) as f3
        FROM a 
        LEFT JOIN b on b.f4 = a.f4
    ) S
    WHERE S.f3 = 'something'
    

    This is actually less efficient than replacing the value with the formula itself as it will require a full scan. To improve performance (but decrease readability) you can use this query:

    SELECT a.f1 aF1, b.f1 bF1,
      IF(a.f3 <> '', a.f3, b.f3) as f3
    FROM a 
    LEFT JOIN b on b.f4 = a.f4
    WHERE IF(a.f3 <> '', a.f3, b.f3) = 'something'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im building a forum and now im gonna code the thread page. is there
A little background on the application that I am gonna talk about in the
I'm gonna trying to explain as good as I can but, it's really hard
My group is thinking about switching our platform for web UI from ASP.net to
Maybe this is gonna sound naive and all, but is there something even remotely
I'm gonna insert a Separator in a ListView in WPF , something like this
I am gonna have a validation of countries when users register. For example only
I know I'm gonna get down votes, but I have to make sure if
Ok when im gonna make reports with Java I use iReport for JasperReports Template
I'm gonna create two div tags with CSS that appear in the page like

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.