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
https://forums.phpfreaks.com/topic/128492-super-dynamic-sql-selects-and-inserts/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.