Solved

Can a result be accomplish with just one query?

Posted on 2011-02-19
2
399 Views
Last Modified: 2012-05-11
I have two tables (table1, table2) with description of a product (a car) in these two tables the car field is a common field. In the first table de date of when the car was painted is storage, in table2 the when it was delivered.  How can I accomplish with a query a result as table 3 shown in picture? I need to show all the cars numbers from both tables in one column and in two column show when the car was either painted of delivered.

Thanks in advance for the help

tables.bmp
0
Comment
Question by:Exl04
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 34935474
SELECT t1.[CarNumber], t1.[DatePainted], t2.[DateDelivered]
FROM [table1] t1 INNER JOIN
    [table2] t2 ON t1.[CarNumber] = t2.[CarNumber]
UNION ALL
SELECT t1.[CarNumber], t1.[DatePainted], Null AS [DateDelivered]
FROM [table1] t1 LEFT JOIN
    [table2] t2 ON t1.[CarNumber] = t2.[CarNumber]
WHERE t2.[CarNumber] Is Null
UNION ALL
SELECT t2.[CarNumber], Null AS [DatePainted], t2.[DateDelivered]
FROM [table1] t1 RIGHT JOIN
    [table2] t2 ON t1.[CarNumber] = t2.[CarNumber]
WHERE t1.[CarNumber] Is Null
0
 
LVL 1

Author Closing Comment

by:Exl04
ID: 34935533
Great Patrick, exacly what I needed!

Thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now