Query 2 un realated tables into 1 list

buratti

Registered User.
Local time
Today, 14:40
Joined
Jul 8, 2009
Messages
234
I am trying to query together 2 tables and have the end result just a list of all records together in 1 list
For example, lets say table 1 has 50 records and table 2 has 25 records. I need the query to display all 75 of those records. Each of those tables have different fields and are in no way related to each other. So the results would have all fields of both tables combined, and for each record the table 1 fields would be blank for table 2 records and vice versa. Any suggestions?
 
I am trying to query together 2 tables and have the end result just a list of all records together in 1 list
For example, lets say table 1 has 50 records and table 2 has 25 records. I need the query to display all 75 of those records. Each of those tables have different fields and are in no way related to each other. So the results would have all fields of both tables combined, and for each record the table 1 fields would be blank for table 2 records and vice versa. Any suggestions?

While I am not sure as to the purpose of the request, I would think a UNION (or maybe a UNION ALL) Query could handle this. Consider the simplest case that I can imagine:
Code:
Table1
    Item1
 
Table2
    Item2
    Item3
 
SELECT Item1, "" AS Item2, "" AS Item3 From Table1 
UNION  SELECT "" AS Item1, Item2, Item3 From Table2
ORDER BY Item1, Item2, Item3

The ORDER BY is optional and intended to separate values that were SELECTed from Table1 from values that were SELECTed from Table2. Is something like this what you are looking for?
 
Could you supply some more information? Maybe the field names, show some sample data of the records in both tables and your desired outcome.
 
Oops... I was a bit late there. My post actually took a while to come through.
 
Actually, mine did too, I am also noticing something strange about the display areas for Code and for Quotes
 
One thing I noticed is that the boxes surrounding the Code and Quotes sections were not complete (the lines on hte right side and bottom are missing). Despite this, it appears that the functionality has not changed, only the appearance. I assumed that it might be a video setting on my monitor, but was unable to make any changes to the display. Attached is a screenshot.
 

Attachments

  • Screenshot.jpg
    Screenshot.jpg
    94 KB · Views: 86
Same on mine too. It is probably their attempt to make a 3-D effect. The reply box has it too.
 
Thanks for some suggestions. I never worked with union queries, but I tried it out a little, and not quite the results I needed. I attached a DB with a silly example of what I need, but it should be understandable.

I need to join table 1 and table 2 together IN A QUERY, so the results would look like table 3. Table 3 was created by 2 append queries, but I was wondering if its possible to create it as a query, eliminating duplicate/redundant data by creating a table like i just did?
 

Attachments

I'm just wondering if it's worth using a union query. Are you trying to do this so you can create a report?

By the way, here's your query:
Code:
SELECT Table2.Show, Table2.Time, Table2.Channel, Null as Animal, Null As Color, Null As Age, Null As Region
FROM Table1, Table2
UNION
SELECT Null, Null, Null, Animal, Color, Age, Region
FROM Table1;
 
Last edited:
thanks thats exactly what I needed. The actual use for this is as follows: In simplest explanation, I have to different order tables (unrelated to each other). I need a form based on those tables listing ALL orders from each table. So even though its a form, i guess technically it is a report that I need.
 
Maybe look into using a report for this and instead of the union you can probably use subreports. One sub for each table.

NB: Slight error in the sql statement - remove Table1 in the first FROM line so it should only be FROM table2.
 

Users who are viewing this thread

Back
Top Bottom