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
 Joining a 2 new queries into 1

Author  Topic 

Kittyness
Starting Member

8 Posts

Posted - 2013-07-04 : 07:16:26
I use access to design my SQL queries (as I'm a newbie) and have written the following :

Qry_LastInv1

SELECT Max(DataElectricity.Date) AS MaxOfDate, DataElectricity.Point_Id
FROM DataElectricity
GROUP BY DataElectricity.Point_Id
ORDER BY DataElectricity.Point_Id;


Qry_LatestElecReadings

SELECT Lookup.Lookup_Name AS [Group], Contacts.Name AS Site, Points.Number AS MPAN, DataElectricity.Date, DataElectricity.M1_Present, DataElectricity.M2_Present, DataElectricity.M3_Present, DataElectricity.M4_Present, DataElectricity.M5_Present, DataElectricity.M6_Present, DataElectricity.M7_Present, DataElectricity.M8_Present
FROM Lookup INNER JOIN (([Qry_LastInv 1] INNER JOIN DataElectricity ON ([Qry_LastInv 1].MaxOfDate = DataElectricity.Date) AND ([Qry_LastInv 1].Point_Id = DataElectricity.Point_Id)) INNER JOIN (Points INNER JOIN Contacts ON Points.Contacts_Id = Contacts.Id) ON [Qry_LastInv 1].Point_Id = Points.Id) ON Lookup.Lookup_Id = Contacts.Group_1
WHERE (((DataElectricity.Direct)="D"))
ORDER BY Lookup.Lookup_Name, Contacts.Name;


How do I join them together ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-04 : 07:45:06
what are the common columns that can be used for join?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -