2

Suppose I wanna do a join between table 1 and other tables...table 1 contains a column that specifies which table that row should be joined with

eg:

Table 1:

entry | tableName
333   | table3
4444  | table2
111   | table3

so 333 should be joined with table3, 4444 with table2, etc....

is there a way to specify mysql queries to use the column values like this as the name of the table to be joined with the entry?

kamikaze_pilot
  • 14,304
  • 35
  • 111
  • 171

2 Answers2

1

You will have to fetch the result set from this table where you have the entry, table details & build a dynamic query. You will not be able to do this in a single query.

Not sure why you have such requirement. It's always best to know what are the tables & relationships to get the best possible join.

isobar
  • 1,165
  • 8
  • 10
0

You can only do that if you build a dynamic query.

Icarus
  • 63,293
  • 14
  • 100
  • 115