比如我有table1  和table2  
这两个表中的字段都是 id,name
现在要在两个表中查询name='中国' 的数据怎么写查询语句注明:  这两个表中的字段都是id和name   但是这两个表中的id没有关系 比如table1和table2表中的数据分别是:table1中id            name
1             中国
2             上海
3             北京
4             中国table2中id            name
1             美国
2             英国
3             中国
4             北京
5             广东
6             江西现在要查询两个表中的name='中国'  

解决方案 »

  1.   

    select * from 
    (
    select id,name from table1
    union
    select id,name from table2
    ) a
    where a.name='中国'
      

  2.   

    不知道你要查询到什么的
    可以用union
      

  3.   

    union 是将union前后俩天sql语句视为一条执行
      

  4.   

    select * from 

    select id,name from table1 
    union 
    select id,name from table2 
    ) a 
    where a.name='中国' 
      

  5.   

    我给你想了个笨法
    DataSet ds = new DataSet();
    DataSet ds1 = new DataSet();select id,name from table1 
    放到ds中 
    select id,name from table2 
    放到ds1中        for (int i; i < ds.Tables[0].Columns.Count; i++)
            {
                ds1.Tables[0].Columns.Add(ds.Tables[0].Columns[i]);
            }
      

  6.   

    sql = "select Title,ColumnCode,id from(select Title,ColumnCode,id from Xk_Content where (title like '%" + key + "%' or content like '%" + key + "%') union all select content,nickname,gbook_id from guestbook where (content like '%" + key + "%' or reply like '%" + key + "%') union all select title,pic,id from pictrue where content like '%" + key + "%' or title like '%" + key + "%') as soso";这些都是本人在实际工作中用到的,均为原创,若有不懂的请恢复
    http://ttgsh.cn/thread-104-1-1.html
      

  7.   

    http://ttgsh.cn/thread-104-1-1.html