Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query with joins

Author  Topic 

rdl
Starting Member

25 Posts

Posted - 2011-05-18 : 15:58:44
Hi,

I am finding it a problem to do joins using the below query.

I want to show the details of the owner in the stolen vehicles report.

I have the following:

Table 1: vehicle has fields RegistrationNo, ID (identity card of owner which is foreign key)

Table 2: person has fields ID, Surname, Name.

Table 3: vehiclereport has fields RegistrationNo, Relation, RelationDate.
(Note that relation is stolen or recovered)

I have the following query to list the current stolen vehicles:
SELECT *
FROM reportvehicle A
WHERE A.Relation = 'Stolen'
AND NOT EXISTS (SELECT * from reportvehicle B
WHERE B.RegistrationNo = A.RegistrationNo AND B.Relation = 'Recovered'
AND B.AlertDate > A.AlertDate)";

Can someone help me to include also the ID, Surname, Name of the owner please.

Thankyou.
rdl

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-18 : 16:08:19
I know it's a long thread, but let's keep this going in the original:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=160753
Go to Top of Page
   

- Advertisement -