How to select from multiple tables without a JOIN

0 votes
What is the simplest way to choose data from two tables and have them show up as distinct rows rather than being joined? Both tables have fields that are the same or comparable, and I want to do an aggregate operation on them, such as averaging all the rows from both tables that occurred in the same month.

I have two tables, for instance, one of which displays transactions from one system and the other of which displays transactions from a different system. Is it possible to extract each transaction from the two tables as a distinct row? I would like the return to include 50 rows if table 1 contained 20 records and table 2 contained 30 records.
Sep 11, 2022 in Database by Kithuzzz
• 38,000 points
6,392 views

1 answer to this question.

0 votes

Try this:

SELECT ...
FROM (
    SELECT f1,f2,f3 FROM table1
    UNION
    SELECT f1,f2,f3 FROM table2
)
WHERE ...

I hope this helps you.

To know more about SQL, It's recommended to join MS SQL Course today.

answered Sep 12, 2022 by narikkadan
• 63,600 points

Related Questions In Database

0 votes
1 answer

How to drop all tables from a database with one SQL query?

Use the INFORMATION_SCHEMA.TABLES view to get the ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
9,009 views
0 votes
0 answers

How to fetch the nth highest salary from a table without using TOP and sub-query?

I was recently requested to create a ...READ MORE

Aug 25, 2022 in Database by Kithuzzz
• 38,000 points
1,414 views
0 votes
0 answers

How to create a table from select query result in SQL Server 2008

I tried to build a table from ...READ MORE

Sep 2, 2022 in Database by Kithuzzz
• 38,000 points
865 views
+2 votes
1 answer

How to export data from MySql to a CSV file?

If you are using MySql workbench then ...READ MORE

answered Jan 4, 2019 in Database by Priyaj
• 58,020 points
1,584 views
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
1,852 views
0 votes
1 answer

Creating A New MySQL User In Amazon RDS Environment

AWS RDS security groups documentation (a common ...READ MORE

answered Jul 18, 2018 in AWS by Priyaj
• 58,020 points
2,082 views
0 votes
1 answer

Using conditional to execute a command in salt

You can use unless inside your state ...READ MORE

answered Jul 23, 2018 in Other DevOps Questions by DareDev
• 6,890 points
2,093 views
0 votes
1 answer

SQL SELECT from multiple tables

Try this: SELECT p.pid, p.cid, p.pname, c1.name1, c2.name2 FROM ...READ MORE

answered Sep 16, 2022 in Database by narikkadan
• 63,600 points
638 views
0 votes
1 answer

How to convert date to a format `mm/dd/yyyy`

Your data is already in varchar, thus ...READ MORE

answered Sep 10, 2022 in Database by narikkadan
• 63,600 points
4,255 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP