MySQL join tables where table name is a field of another table

前端 未结 3 1248
太阳男子
太阳男子 2021-01-12 08:30

I have 5 tables. One primary and 4 additional (they have different columns).

  1. objects
  2. obj_mobiles
  3. obj_tablets
  4. obj_computers
3条回答
  •  醉梦人生
    2021-01-12 08:52

    USE CONCAT to create your prepare statement. eg.

    @sql = CONCAT('SELECT * FROM objects AS object LEFT JOIN ', @tbl, ' AS info ON object.id = info.obj_id');
    PREPARE stmnt FROM @sql;
    ...
    

提交回复
热议问题