几张表,简单起见,贴两张表的图,其他表同理。check_log表:
NewsDoc表:
想要实现这样一个功能:
1.如果 check_log.table_name字段的内容是NewsDoc,则执行:
select * 
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID2.如果check_log.table_name字段的内容是Orgnization0,则执行:
select * 
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID3.如果check_log.table_name字段的内容是InvestDoc,则执行:
select * 
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID不知道表达清楚了没有,请大家给看看,这样一个查询能不能在一个sql语句中写出来请教,多谢!

解决方案 »

  1.   

    没有图  
    不过我感觉应该是3个left join
      

  2.   

    sql的动态注入可以实现!
    看不清你的图片
      

  3.   

    如果字段名,类型,顺序,数量都相同,则用union allselect * 
    from check_log, NewsDoc 
    where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
    union all
    select * 
    from check_log, Orgnization0 
    where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
    union all
    select * 
    from check_log, InvestDoc 
    where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'
      

  4.   

    如果字段名,类型,顺序,数量都相同,则用union allselect * 
    from check_log, NewsDoc 
    where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
    union all
    select * 
    from check_log, Orgnization0 
    where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
    union all
    select * 
    from check_log, InvestDoc 
    where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'如果上述不行,就自己更改字段名,类型,顺序,数量都相同,至少如下是行得。
    select check_log.* 
    from check_log, NewsDoc 
    where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
    union all
    select check_log.* 
    from check_log, Orgnization0 
    where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
    union all
    select check_log.* 
    from check_log, InvestDoc 
    where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'
      

  5.   


    那就一个一个写.如果字段名,类型,顺序,数量都相同,则用union allselect * 
    from check_log, NewsDoc 
    where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
    union all
    select * 
    from check_log, Orgnization0 
    where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
    union all
    select * 
    from check_log, InvestDoc 
    where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'如果上述不行,就自己更改字段名,类型,顺序,数量都相同,至少如下是行得。
    select check_log.* 
    from check_log, NewsDoc 
    where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
    union all
    select check_log.* 
    from check_log, Orgnization0 
    where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
    union all
    select check_log.* 
    from check_log, InvestDoc 
    where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'
      

  6.   


    你自己多写了一个,我也没仔细看.应该如下:如果上述不行,就自己更改字段名,类型,顺序,数量都相同,至少如下是行得。
    select check_log.* 
    from check_log, NewsDoc 
    where check_log.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
    union all
    select check_log.* 
    from check_log, Orgnization0 
    where check_log.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
    union all
    select check_log.* 
    from check_log, InvestDoc 
    where check_log.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'