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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:06:12+00:00 2026-05-14T19:06:12+00:00

I have a table Action with a (part of the) structure like this: Action

  • 0

I have a table Action with a (part of the) structure like this:

Action:
ActionTypeID,
ActionConnectionID
…

ActionTypeID refers to types 1-5 which correspond to different tables (1=Pro, 2=Project etc.)
ActionConnectionID is the primaryKey in the corresponding table;

ie. ActionTypeID=1,
ActionConnectionID=43 -> would point
to Pro.ProID=43 and ActionTypeID=2,
ActionConnectionID=233 -> would point
to Project.ProjectID=233

Is there a way to ‘dynamically join the different tables depending on the value in the ActionTypeID column?
ie. for records with the ActionTypeID=1 this would be:

Select Action.* 
From Action Left Join Pro On Action.ActionConnectionID=Pro.ProID

for records with the ActionTypeID=2 this would be:

Select Action.* 
From Action Left Join Project On Action.ActionConnectionID=Project.ProjectID

etc.

If this is not possible to accomplish in one query I will have to loop over all the possible ActionTypes and perform the query and then afterwards join the data in one query again – that would be possible, but doesnt sound like the most efficient way 🙂

  • 1 1 Answer
  • 1 View
  • 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-14T19:06:13+00:00Added an answer on May 14, 2026 at 7:06 pm

    Something like this should do:

    Select Action.*  
    From   Action 
           Left Join Pro 
                 ON Action.ActionConnectionID=Pro.ProID and ActionTypeID=1
           Left Join Project 
                 ON Action.ActionConnectionID=Project.ProjectID and ActionTypeID=2
    

    If that doesn’t work for either try using dynamic sql which is a bad solution or properly normalize your data.

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

Sidebar

Related Questions

I have this form:- <form action=> <table border=0> <td colspan=2 class=instruction>Select your desired option
I have a simple span like so <span class=action removeAction>Remove</span> This span is within
I have something like this: //html <div class=panel> <div class=tools> <a href=#action1>Action 1</a> <a
I have a table which basically contains a Person_ID, Action, TimeStamp and using Microsoft
I have an SQL table written in MSSQL: create table [action] ( action_id bigint
I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION
I have two database tables with the following structure: actions: action_id int(11) primary key
I have table definition like below: Place (id, name) Review (id, userid, placeid) Favorite
I have 2 tables: create table numbers2 ( id1 int IDENTITY(1,1) not null, id2
I have an action in a model that adds a record to a table.

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.