我有2个表
第一个,Inquiry1
第二个,Inquiry2两个表完全一样要一条SQL 查出这2个表的所有title  条件是根据like  textbox   
还有 不建关系视图  可以吗 ?

解决方案 »

  1.   

    select * from Inquiry1 where title like '"+this.textbox.Text+"' UNION ALL select * from Inquiry2 where title like '"+this.textbox.Text+"'
      

  2.   

    select [title] form [Inquiry1] where [title] like '%abc%'
    union
    select [title] form [Inquiry2] where [title] like '%abc%'
      

  3.   

    union all 会把重复的记录也查询出来,如果不想要重复的,用 union 即可。
      

  4.   

    string sql = string.Format
    (
      @"
      select [title] form [Inquiry1] where [title] like '%{0}%'
      union
      select [title] form [Inquiry2] where [title] like '%{0}%'
      ",
      textbox.Text.Trim()
    )
      

  5.   

    string sql = string.Format
    (
      @"
      select [title],'表A' AS FromTable form [Inquiry1] where [title] like '%{0}%'
      union
      select [title],'表B' AS FromTable form [Inquiry2] where [title] like '%{0}%'
      ",
      textbox.Text.Trim()
    )你查的时候加一列标识不就好了.
      

  6.   

    string sql = string.Format ( "select [title] from Inquiry1 ,Inquiry2  where [title] like '{0}%'", textbox.Text.Trim());