Question

i have a db like this:

Table1:

  • id
  • id_item
  • table (enum: 'table2','table3','table4')

table2:

  • id
  • value

table3:

  • id
  • value

table4: [...]

And i want to run a query like this:

SELECT t1.id, t2.value FROM table1 AS t1
LEFT JOIN table1.table as t2 ON t1.id_item=t2.id

Is it possible? or i have to select first table1 and after the value? ( sorry for my bad eng :) )

Was it helpful?

Solution

If I understood the last column in Table 1 correctly and it is just a string, you can't.

You cannot write a column into the FORM-clausal and wait for mysql to evaluate it for every row and find the correct table to join it with.

To do this you will need to create a view where you will have the data from all the tables, together with the table name as an additional column. Afterwards you can perform a join like that between Table1 and the new view

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top