I have two tables, say table1 with two rows of data say row11 and row12 and table2 with 3 rows of data sat row21, row22, row23
Can anyone provide me with the SQL to create a query that returns
row11
row12
row21
row22
row23
Note: I dont want to create a new table just return the data.
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 has strict rules for appending data: Both tables must have the same number of columns. The columns must have the same data types in the same order as the first table.
An Append query takes a group of records from one or more tables or queries in your database and adds them to another table. Append queries are especially useful for importing information into a table.
Use UNION ALL
, based on the example data:
SELECT * FROM TABLE1
UNION ALL
SELECT * FROM TABLE2
UNION
removes duplicates - if both tables each had a row whose values were "rowx, 1", the query will return one row, not two. This also makes UNION
slower than UNION ALL
, because UNION ALL
does not remove duplicates. Know your data, and use appropriately.
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