select * from Inquiry1 where title like '"+this.textbox.Text+"' UNION ALL select * from Inquiry2 where title like '"+this.textbox.Text+"'
select [title] form [Inquiry1] where [title] like '%abc%' union select [title] form [Inquiry2] where [title] like '%abc%'
union all 会把重复的记录也查询出来,如果不想要重复的,用 union 即可。
string sql = string.Format ( @" select [title] form [Inquiry1] where [title] like '%{0}%' union select [title] form [Inquiry2] where [title] like '%{0}%' ", textbox.Text.Trim() )
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() )你查的时候加一列标识不就好了.
string sql = string.Format ( "select [title] from Inquiry1 ,Inquiry2 where [title] like '{0}%'", textbox.Text.Trim());
union
select [title] form [Inquiry2] where [title] like '%abc%'
(
@"
select [title] form [Inquiry1] where [title] like '%{0}%'
union
select [title] form [Inquiry2] where [title] like '%{0}%'
",
textbox.Text.Trim()
)
(
@"
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()
)你查的时候加一列标识不就好了.