查询从sql server中的多个表中获取给定数据? [英] query to get given data from multiple tables in sql server ?

查看:169
本文介绍了查询从sql server中的多个表中获取给定数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有3个表,我在所有3个表中都有一个列新闻varchar(max),我想搜索所有表中的给定文本,并想知道文本存在于哪个表中。是查询?

i have 3 tables in my database and i have a column news varchar(max) in all 3 tables and i want to search a given text in all the tables and want to know in which table that text is present.what will be the query?

推荐答案

您可以对每个表使用全文搜索:

You can use full text search for each table:
SELECT id,news FROM products WHERE CONTAINS(news, "words to search here")



请参考链接: SQL全文搜索编程 [ ^ ]


假设有3个表员工,学生,雇主,并且所有三个表都有一个地址列

使用此查询查看文本可用的表格。



lets say there are 3 tables employee,student,employer and all three has a Address column
use this query to see in which table the text is available.

SELECT		a.Address as employeeAddress,
			b.Address as studentaddress,
			c.Address as employeraddress
FROM		employee	a left outer join
			student		b
			on a.empcode = b.stid
			left outer join
			employer	c
			on b.stid = c.EmployerCode			
where		(
			a.Address	like '%texttobesearched%'
			OR
			b.Address	like '%texttobesearched%'
			OR
			c.Address	LIKE '%texttobesearched%'
			)





希望这有帮助!



Hope this helps!


这篇关于查询从sql server中的多个表中获取给定数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆