SQL 附加来自两个查询的结果并作为单个表输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4619090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:47:25  来源:igfitidea点击:

Append Results from two queries and output as a single table

sqlsql-serversql-server-2008

提问by tHeSiD

I have two queries that I have to run, I cannon join them But their resultant tables have the same structrure.

我有两个必须运行的查询,我无法加入它们但是它们的结果表具有相同的结构。

For example I have

例如我有

select * from products where producttype=magazine

select * from products where producttype = book

I have to combine the result of these two queries, and then output it as one single result. I have to do this inside a stored procedure.

我必须将这两个查询的结果结合起来,然后将其作为一个结果输出。我必须在存储过程中执行此操作。

PS These are just examples I provided, i have a complex table structure. The main thing is I cannot join them.

PS 这些只是我提供的例子,我有一个复杂的表结构。主要是我不能加入他们。

回答by Jahan

select * from products where producttype=magazine
union
select * from products where producttype = book

回答by bernd_k

I think that magazin and book are varchar values and not columns in your table

我认为 magazin 和 book 是 varchar 值而不是表中的列

select * from products where producttype in ('magazine', 'book');

回答by DRapp

Or, just a single query...

或者,只是一个查询...

select *  
   from products 
   where producttype = magazine
      or producttype = book