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.
The SQL UNION statement joins together the output of two or more SELECT statements into a single result set. The field names from the tables need not match, but they must be entered in the same order.
On the Home tab, in the View group, click View, and then click Design View. On the Design tab, in the Query Type group, click Append. The Append dialog box appears. Next, you specify whether to append records to a table in the current database, or to a table in a different database.
SQL JOIN. A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.
select * from products where producttype=magazine
union
select * from products where producttype = book
I think that magazin and book are varchar values and not columns in your table
select * from products where producttype in ('magazine', 'book');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With