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

  • Home
  • SEARCH
  • 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 8196987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:38:43+00:00 2026-06-07T05:38:43+00:00

Im experimenting with the following idea. I am trying to build a fallback system

  • 0

Im experimenting with the following idea. I am trying to build a fallback system all in the single query. Here is some background information:

posts_table
id, timestamp

posts_content_table
id, post_id, language_id, title, description

The goal here is to query posts_table then in the same query, join the posts_content_table using a fallback system. So if i search for post content with a language_id that doesn’t exist it should be able to fallback to an language_id that does contain content. It should allow for multiple levels of fallbacks.

Example:

SELECT p.id FROM posts_table AS p 

LEFT OUTER JOIN posts_content_table AS pc ON (p.id=pc.post_id AND pc.language_id=1)
LEFT OUTER JOIN posts_content_table AS pc2 ON (p.id=pc2.post_id AND pc2.language_id=2)
LEFT OUTER JOIN posts_content_table AS pc3 ON (p.id=pc3.post_id AND pc3.language_id=3)

Naturally what will happen is when it returns data which is not null, that data should be used as the final result. So this brings me to CASES. How would i implement CASES to work in this way? Would the following suffice?

SELECT p.id, CASE title
WHEN pc.title is Null THEN pc2.title
WHEN pc2.title is Null THEN ps3.title
WHEN pc3.title is Null THEN '-'
END
FROM posts_table AS p 

LEFT OUTER JOIN posts_content_table AS pc ON (p.id=pc.post_id AND pc.language_id=1)
LEFT OUTER JOIN posts_content_table AS pc ON (p.id=pc.post_id AND pc.language_id=2)
LEFT OUTER JOIN posts_content_table AS pc ON (p.id=pc.post_id AND pc.language_id=3)
  • 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-06-07T05:38:43+00:00Added an answer on June 7, 2026 at 5:38 am

    This is the purpose of COALESCE(), which returns the first non-null of its arguments:

    SELECT 
      p.id, 
      COALESCE(pc.title, pc2.title, pc3.title, '-') AS title
    FROM posts_table AS p 
    LEFT OUTER JOIN posts_content_table AS pc ON (p.id=pc.post_id AND pc.language_id=1)
    LEFT OUTER JOIN posts_content_table AS pc2 ON (p.id=pc2.post_id AND pc2.language_id=2)
    LEFT OUTER JOIN posts_content_table AS pc3 ON (p.id=pc3.post_id AND pc3.language_id=3)
    

    (Note: I fixed your table aliases – they were all pc and I assume you meant to alias as pc, pc2, pc3)

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

Sidebar

Related Questions

I've been experimenting with jQuery Mobile. I am trying to implement the following When
The following is an excerpt from some code that I'm experimenting with: has buffer
I'm experimenting with JPA queries but keep getting an error on the following query
I am just experimenting on Mutex and wrote the following code. using System; using
I'm experimenting with the following mockable repository pattern: public interface IEmployeeRepository { ITable<Employee> Employees
When I wrote the following snippet for experimenting purposes, it raised the hover-error (see
I am experimenting with OpenCL programming. I was following the article in http://www.thebigblob.com/getting-started-with-opencl-and-gpu-computing/ When
I am experimenting with JavaScript Inheritance. Basically, I am following this tutorial. I see
I am experiencing a problem with the following code in some versions of Internet
Experimenting with Scala... I'm trying to define something analogous to the @ hack in

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.