存储过程的sql查询

发布于 2024-11-07 08:37:35 字数 263 浏览 0 评论 0原文

我有五个表“ArtBook、Eng、comm、Law、mgt”,每个表都有相同的列,我想通过其 id 搜索该特定书籍的所有信息 例如-

select * from ArtBook,Eng,Comm,Law,mgt where @BookId=ArtBooks.BookId
or @BookId=CommBooks.BookId
or @BookId=Eng.BookId
or @BookId=Law.BookId
or @BookId=mgt.BookId

I have five tables "ArtBook,Eng,comm,Law,mgt" and every table has a same column and i want to be search all the information that particular book by its id
e.g-

select * from ArtBook,Eng,Comm,Law,mgt where @BookId=ArtBooks.BookId
or @BookId=CommBooks.BookId
or @BookId=Eng.BookId
or @BookId=Law.BookId
or @BookId=mgt.BookId

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最单纯的乌龟 2024-11-14 08:37:35

如果所有表都存储不同类别的书籍,则将它们合并回一个表并添加“类别”列。出于您所演示的原因,像这样分类到单独的表中并不是一个好主意。

If all the tables store books of different categories, then combine them back into one table and add a 'category' column. Categorising into separate tables like this isn't a good idea for the reasons you've demonstrated.

维持三分热 2024-11-14 08:37:35
select * 
from ArtBook
where BookId = @BookId
union all
select * 
from Eng
where BookId = @BookId
union all
select * 
from Comm
where BookId = @BookId
union all
select * 
from Law
where BookId = @BookId
union all
select * 
from Mgt
where BookId = @BookId
select * 
from ArtBook
where BookId = @BookId
union all
select * 
from Eng
where BookId = @BookId
union all
select * 
from Comm
where BookId = @BookId
union all
select * 
from Law
where BookId = @BookId
union all
select * 
from Mgt
where BookId = @BookId
安人多梦 2024-11-14 08:37:35

可以使用 UNION 或 UNION ALL 运算符。

(SELECT * FROM ArtBook)
UNION ALL
(SELECT * FROM Eng)
...
WHERE @BookId=ArtBooks.BookId or
       @BookId=CommBooks.BookId or 
       @BookId=Eng.BookId or 
       @BookId=Law.BookId or 
       @BookId=mgt.BookId

等等,等等。尽管您可能会考虑重组数据的存储方式以使此类事情变得更容易。

One could use the UNION or UNION ALL operator.

(SELECT * FROM ArtBook)
UNION ALL
(SELECT * FROM Eng)
...
WHERE @BookId=ArtBooks.BookId or
       @BookId=CommBooks.BookId or 
       @BookId=Eng.BookId or 
       @BookId=Law.BookId or 
       @BookId=mgt.BookId

et cetera, et cetera. Though you may consider restructuring how your data is stored to make this sort of thing easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文