SELECT Table1.[Cont#]
FROM Table1
UNION SELECT Table2.[Cont#]
FROM Table2
GROUP BY [Cont#];
Save this as Query1
Then create a second query, using Query1 as the master table, joining outwards to the original two tables:
SELECT Table1.ID1, Table1.Cust, Query1.[Cont#], Table2.ID2, Table2.Bill
FROM (Query1 LEFT JOIN Table1 ON Query1.[Cont#] = Table1.[Cont#]) LEFT JOIN Table2 ON Query1.[Cont#] = Table2.[Cont#];
I really ought to get to grips with SQL Server someday - I just need a big project that will demand it; I know Access is widely regarded as little more than a toy (although perhaps not by you Zev), It does suck badly on the multi-user aspect and is a bit clunky with very large tables, but I’ve found it remarkably powerful for small business needs.
When I first started learning about relational databases, I used Access and almost always used the Query Builder tool. Now that I’m used to SQL, I can barely use the tool and always write my queries in SQL. However, the Access syntax is clumsy. For example (at least through Access 2K, I didn’t check out 2002), you can’t alias table names. So, you have to type out:
SELECT table1.column1,
table2.column1,
table1.column2
table3.column
FROM table1,
table2,
table3
WHERE table1.column3 = table2.colum2
AND table2.column2 = ...
In T-SQL it’s much easier
SELECT t1.column1,
t2.column1,
t1.column2
t3.column
FROM table1 t1,
table2 t2,
table3 t3
WHERE t1.column3 = t2.colum2
AND t2.column2 = ...
If you ever need help with SQL Server Mangetout, feel free to just drop me an email.
I don’t know jack about Access 2K or 2002, but you can sure as shootin’ alias table names in Access 97. Here’s a working query from one of my '97 databases:
The tables are linked from an Informix database, but I can’t imagine why it wouldn’t work the same way with local Access tables. Nor can I imagine why Microsoft would eliminate this functionality in upgrades. Of course, the syntax might be different, or Microsoft could be managed by idiots, or … well, I’ll stop there.