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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:15:28+00:00 2026-05-27T18:15:28+00:00

This is my situation. I have different tables, by example: TABLE A Name |

  • 0

This is my situation. I have different tables, by example:

TABLE A

Name | Phone              
John   123   
Mick   233

TABLE B

Department | Position          
IT            xxx   
HR            yyy

And the next configuration table is created dynamically via web:

TABLE C

Source | Field  
TABLE A    Name   
TABLE B    Department

When I run the application, I read the Table C and I need to generate the data.
In this case, I need to list all the names from TABLE A and all the departments from TABLE B.

How can I query this? I hope somebody can help me.

Cheers!

  • 1 1 Answer
  • 3 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-27T18:15:28+00:00Added an answer on May 27, 2026 at 6:15 pm

    If you have to do this in sql – which I would not recommend if you can not trust the content of TABLE C – then you will need to construct a variable that contains the sql query, then execute that sql query dynamically. How to do this will entirely depend on your DBMS. An example in MySQL (which assumes that TABLE C has only one row):

    SELECT @sql:=CONCAT("SELECT ",field," FROM ",source) FROM TABLE_C;
    PREPARE s1 FROM @sql;
    EXECUTE s1;
    

    SQL Server syntax:

    DECLARE @sql nvarchar(max)
    SELECT @sql = "SELECT " + field + " FROM " + source FROM TABLE_C
    EXEC sp_executesql @sql
    GO
    

    Since TABLE C will certainly have more than one row you will have to iterate through TABLE C. This can be done with a CURSOR, and again the exact details will be dependent on your DBMS.

    Importantly, be aware that this is very dangerous if as you state TABLE C is created from the web. You have no guarantee what is in the FIELD and SOURCE fields: they could be filled with a sql injection attack by anyone with a little SQL knowledge. What you may need to do is safely validate that TABLE C’s contents are actual tables/columns via safely parameterized database meta-queries.

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

Sidebar

Related Questions

Take for example this situation. You have 3 models: Poet - Represents the author
In this situation I have two models, Comment and Score. The relationship is defined
During coding I frequently encounter this situation: I have several objects ( ConcreteType1 ,
I have this situation: { float foo[10]; for (int i = 0; i <
I have this situation where I want to display a list of Administration objects
We have this situation: Window Keyboard ^ ^ | / ApplicationWindow so class Window
I have this situation: interface MessageListener { void onMessageReceipt(Message message); } class MessageReceiver {
I have this situation: There are a login page with a login form (form
So, I have this situation where I need to see if an object is
this is my situation: I have two org.w3c.dom.Document created from two xml files. What

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.