Add results from two queries and output as a separate table

I have two queries that I have to fulfill, I can join them, but their resulting tables have the same structure.

For example, I have

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

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

PS These are just the examples that I presented, I have a complex table structure. Most importantly, I can’t join them.

+8
sql sql-server sql-server-2008
source share
3 answers
 select * from products where producttype=magazine union select * from products where producttype = book 
+26
source share

I think there are varchar values ​​in the log and book, not the columns in the table.

 select * from products where producttype in ('magazine', 'book'); 
+9
source share

Or just one request ...

 select * from products where producttype = magazine or producttype = book 
+7
source share

Source: https://habr.com/ru/post/650773/


All Articles