Jump to content

Super-Dynamic SQL SELECTS and INSERTS


kodekamel

Recommended Posts

 

I want to select data that will have to be pieced together from several tables.  This data is obscured beyond recognition.  Consider each field is being stored in a separate.  There is a separate table that connects the data to form a single "object".

 

objects(ObjectID,ObjectType)  <<<  objects has one record...  That one "thing" is what we're talking about.

 

object_relations(ID,ObjectID,TableID,DataID)  <<< This table would connect Data to the Object, and tell us where to find it.

 

object_relation_tables(TableID,TableName)  <<< Holds full text table names .

 

object_names(ID,DataValue)  <<<  Holds a field called names.

 

object_descriptions(ID,DataValue)  <<<  Holds the descriptions.

 

 

With that said.  Please avoid calling me an idiot.  I know I know.. WTF is the point.  I'm not getting into that.  Please just try to help.

 

 

I would love to be able to retrieve data with one select.  I don't know what to call it, or how to search it.  My question is... Is this possible and how do I do it?

 

Any suggestions are appreciated. 

 

FYI...  My client will not dismiss this theory, so I have to get it done somehow.  Even suggestions on how to minimize the number of statements would be helpful.

 

 

Link to comment
Share on other sites

Alright... Let me simplify...  Since I have no replys... I assume I have not explained clearly.

 

I am trying make a select statement that selects from different tables depending on the data that exists for an object.

 

Example.

 

  Object1 has a name in the o_name table.

  Object2 does not have a name in the o_name table, but it does has a description in the o_description table.

 

  So here we go.  I think MySql variables can help with this problem.. but i'm not sure how.

 

  I have an object table.  I have an object_map table... and I have an infinate number of tables that hold data related to the object.  The object_map table relates ObjectID with TableID and DataID. 

 

  I want to look up the value of DataID in the table that is related to TableID. 

 

This does not work..... But i'll also give a SQL example.

 

SELECT ot.DV, tn.TableName FROM object_map as om JOIN object_tables as tn ON om.TableID = tn.ID JOIN (@tn.TableName) as ot ON ot.ID=om.DataID

 

It's that (@tn.TableName) as ot that i'm trying to figure out...  The table name that I want to join is stored in object_tables...  CAN I use it in a SQL statement?  if so... HOW?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.