SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Joining a 2 new queries into 1
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kittyness
Starting Member

United Kingdom
8 Posts

Posted - 07/04/2013 :  07:16:26  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 07/04/2013 :  07:45:06  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000