I'm looking for query that selects different column name, dynamically, by variable.
Suppose I have that contains my "dynamic columns" I'd like to select , something like this:
SELECT `ObjectID`,`ObjectLabel` FROM `modules_forms_objects`
+----------+---------------+ | ObjectID | ObjectLabel | +----------+---------------+ | 71 | Join Date | | 72 | Active | +----------+---------------+
Now, I've got one more table, which it's columns called by the "ObjectID" as above. Here:
SELECT `data_id`,`71`,`72` FROM `7`
+---------+---------------------+------+ | data_id | 71 | 72 | +---------+---------------------+------+ | 1 | 0000-00-00 00:00:00 | NULL | +---------+---------------------+------+
I want to join a "Value" column to the first table, and this'll contain the Value from the match Column in the second table. (for example: for ObjectID #72 the value will be NULL).
Ultimately, I want my result to be like this:
+----------+---------------+--------------------+ | ObjectID | ObjectLabel | Value | +----------+---------------+--------------------+ | 71 | Join Date |0000-00-00 00:00:00 | | 72 | Active | NULL | +----------+---------------+--------------------+
When I used traditional "JOIN" I got the all columns for each row, and it seems kind of heavy.
Any ideas? Thanks a lot!