kodekamel Posted October 15, 2008 Share Posted October 15, 2008 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 15, 2008 Share Posted October 15, 2008 I'm sorry, I don't really understand. Quote Link to comment Share on other sites More sharing options...
kodekamel Posted October 21, 2008 Author Share Posted October 21, 2008 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 22, 2008 Share Posted October 22, 2008 The only way to make the table name dynamic is to use a stored procedure. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.