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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:46:40+00:00 2026-05-24T03:46:40+00:00

I tried where I would create a temporary column using case as join_id but

  • 0

I tried where I would create a temporary column using case as join_id but when I tried to left join on it it says the column doesn’t exist

SELECT * , se_users.user_username,
CASE se_album_keys.key_owner_id
WHEN 28 THEN se_album_keys.key_user_id
ELSE se_album_keys.key_owner_id
END  AS key_join_id
FROM se_album_keys
LEFT JOIN se_users ON se_users.user_id=se_album_keys.key_join_id
LIMIT 10;

error:

ERROR 1054 (42S22): Unknown column 'se_album_keys.key_join_id' in 'on clause'

UPDATE:
It’s hard to pick an answer, using IF() as TehShrike suggested indexes can’t be used, but after he suggested this solution for joining table by condition in the chatroom. I realized I was over-analyzing the whole situation and came up with this:

  SELECT se_album_keys.* FROM  se_album_keys 
  LEFT JOIN se_users AS users_see_mine ON se_album_keys.key_owner_id = 28 AND users_see_mine.user_id = se_album_keys.key_user_id 
LEFT JOIN se_users AS users_i_see ON se_album_keys.key_owner_id != 28 AND users_i_see.user_id = se_album_keys.key_owner_id
WHERE se_album_keys.key_user_id=28 OR se_album_keys.key_owner_id=28;

so I’ll leave this question open for a while to see if the experts have something to say. I had already finished coding this and am only interested in learning more about high performance mysql!

  • 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-24T03:46:41+00:00Added an answer on May 24, 2026 at 3:46 am

    You could use an IF() in your join:

    LEFT JOIN users ON users.user_id = IF(album_keys.key_owner_id = 1337, 
      album_keys.key_user_id, album_keys.key_owner_id) 
    

    But be aware that no indexes on the album_keys table will be used!

    Edit: if you JOIN the other table on twice, you can use functions like COALESCE() to show you the relevant one:

    LEFT JOIN users AS users_see_mine ON album_keys.key_owner_id = 1337 
      AND users_see_mine.user_id = album_keys.key_user_id 
    LEFT JOIN users AS users_i_see ON album_keys.key_owner_id != 1337 
      AND users_i_see.user_id = album_keys.key_owner_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using a stored procedure for more than 1.5 years. But I've
I was trying to create an example for deadlock. I tried the following code.
i am used to SQL Server and SQL enterprise studio when using databases in
The OS I'm working on (IBM CNK, which is not Linux, but somewhat POSIX-compliant)
Summary: I want to be able to run a query against an external database
When I am inside Vim and type :ls , Vim lists the buffers. Most
I use Java. I already have a class for a custom object called Subject.
I'm trying to connect Rails to SQL Server. I installed the activerecord-sqlserver-adapter and ruby-odbc
VERSION 1 class Doh { private: static std::map<const std::string, const Doh*> someMap; std::string stringValue_;
This is a problem that has been eating at me for a while, and

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.