Reputation: 21
I have two SQL queries (SQL Server) which give me two results. I would like to merge the two queries to get one overall result. I have tried numerous permutations but none of them seem to work. Here are the two queries:
SELECT DATEPART(YEAR,fld_one) [Year],
DATEPART(QUARTER,fld_one) [Quarter],
COUNT(1) [Licenses]
FROM tbl_licenses
GROUP BY DATEPART(YEAR,fld_one),DATEPART(QUARTER,fld_one)
ORDER BY 1,2
SELECT fld_company
FROM tbl_licenses
WHERE fld_quantity = (SELECT MAX(fld_quantity) FROM tbl_licenses)
Basically I want the fld_quantity value to appear in a column beside YEAR
, QUARTER
and LICENSES
.
Any help would be greatly appreciated.
Upvotes: 0
Views: 65
Reputation: 2388
From the looks of it you need a primary and a foreign key, or at least two columns that you can do a SQL Join with, like date, ID, etc.
Try something like: Select * from tbl_licenses INNER JOIN tbl_licenses_v4 ON tbl_licenses_v4.ID = tbl_licenses.ID
Upvotes: 1