Monday 15 July 2013

database - A single MySQL query for 'bouncing' table selects -


So, ask for simplicity, I have a master table with two fields - the first is a feature and the second attribute value If the second field is set to refer to a value in another table, it is marked in parentheses.

Example:

 MASTER_TABLE: Attr_ID | Attr_Val -------- + ----------- 1 | 23 (Table 1) -> 23rd value from `Table 1`. ... 1 | 42 -> Number 42 1 | 72 (Table 2) -> 722 Price `Table 2` from 3. ... 1 | Txt -> string "txt" 2 | ... 4 | ... Table 1: Val_Id | Price -------- + ----------- 1 | Some_content 2 | .... | .... | .... | ... 23 | Some_content | ... 

Is it possible to execute a single question in SQL (without the need to parse the given results inside the application and require DB) to master MasterTable Reproduced and given & lt; Attr_id & gt; Only get attributes that refer to other tables ( like 23 (Table 1), 72 (Table 2), ... ), then the names of tables from brackets Pars (do such as Table 1, Table 2, ... ) and ( 23, 72, ... ) make a query to get the value ( Example some_content ) from that referenced table?

Here's something I did, and this parses Attr_Val to the table name, but I do not know how to specify the string and then do a query with that string. Prepare pstmt from

  "SELECT * FROM info_schema.tables where TABLESCHEMA = 'my_db_name & gt; And TABLE_NAME =? "; SET @str_tablename = (SELECT table.tablename FROM (SELECT @string: = (SELECT & lt; string_column & gt; FROM & lt; Table & gt; WHERE id = & lt; attr_id & gt;) As a string, @ Loc1: = length (@string) -locate ("(", reverse (strings)) + 2a, @ folk 2: = length (@ string) -locet (")", reverse (@string)) + 1- @ Lok 1 AS, substrate (@ string, @ public1, @ public2) AS tableline) table); & Lt; - It fixes 1 rows which are ok using pstmt @str_tablename; & Lt; - It returns 0 rows  

Any ideas? I like the purity of this approach, if pulled, but I think you should have a maintenance bomb. Are making With such treatment, who needs to be sick?

Nobody has ever said anything about a web site "Man, his data is correct!" They compliment that what is being done with the data I do not suggest that you keep your hands tied behind it on your back. I guarantee that your competitors are not.


No comments:

Post a Comment