Please have patience with me. I not familiar with modern programming. I'm almost 81 years old and had two Fortran II classes at NYU in the mid 1960s. The most I do now are relatively simple batch files that I run from the command prompt on my desktop computer. I'm retired but am a membership VP and on the Board of Directors of a non-profit organization. We are all unpaid volunteers.
I'm using MS Access and had to use SQL because I need to combine data from two tables within the database that are non-relational. I've never used SQL coding before, but doing online research, I got the need information, especially using the UNION statement to get the desired results.
This works:
-------------------------------------
SELECT qryMembershipNotArchivedEmailMailingList.NonMemberID,Title,LastName,FirstName,Email
FROM qryMembershipNotArchivedEmailMailingList
UNION SELECT qryNonMemberPurchaserNotArchivedForEmailing.NonMemberID,Title,LastName,FirstName,Email
FROM qryNonMemberPurchaserNotArchivedForEmailing
ORDER BY LastName, FirstName;
--------------------------------------
But I want a count of LastName from the combination arrived at by the UNION
I tried adding COUNT(LastName) and also tried COUNT(*) and in both instances and when that didn't work, I added GROUP BY Lastname statements, and no matter what I do, or where I put these statements, I always get an error when trying to save it, or in some variations, I can save it but then it won't open, except in design view.
If not a syntax error, then a missing operator error.
Can someone please complete the code that will give a combined count of the LastName from both queries (which are from two non-relational tables within the database).
Also, is in the first example, that works, but does not give me the total count that I want, is there a way to eliminate the Box that first pops-up asking me to enter a parameter for NonMemberID. I just hit enter and the datasheet view opens up. I saw examples of how to do that with a regular Access query, but not one that only has SQL code , as this one does because of the UNION statement (no properties window or anything else).
I saw that I can get my total count when opening the query by selecting home on the ribbon and then selecting the summation symbol menu item for the column or columns. Also the number of records on the bottom shows the total as well. But I would like the total to always show (as a count) so that when I export the query results to Excel, the total shows at the bottom of the Excel worksheet.
Thanks.
I'm using MS Access and had to use SQL because I need to combine data from two tables within the database that are non-relational. I've never used SQL coding before, but doing online research, I got the need information, especially using the UNION statement to get the desired results.
This works:
-------------------------------------
SELECT qryMembershipNotArchivedEmailMailingList.NonMemberID,Title,LastName,FirstName,Email
FROM qryMembershipNotArchivedEmailMailingList
UNION SELECT qryNonMemberPurchaserNotArchivedForEmailing.NonMemberID,Title,LastName,FirstName,Email
FROM qryNonMemberPurchaserNotArchivedForEmailing
ORDER BY LastName, FirstName;
--------------------------------------
But I want a count of LastName from the combination arrived at by the UNION
I tried adding COUNT(LastName) and also tried COUNT(*) and in both instances and when that didn't work, I added GROUP BY Lastname statements, and no matter what I do, or where I put these statements, I always get an error when trying to save it, or in some variations, I can save it but then it won't open, except in design view.
If not a syntax error, then a missing operator error.
Can someone please complete the code that will give a combined count of the LastName from both queries (which are from two non-relational tables within the database).
Also, is in the first example, that works, but does not give me the total count that I want, is there a way to eliminate the Box that first pops-up asking me to enter a parameter for NonMemberID. I just hit enter and the datasheet view opens up. I saw examples of how to do that with a regular Access query, but not one that only has SQL code , as this one does because of the UNION statement (no properties window or anything else).
I saw that I can get my total count when opening the query by selecting home on the ribbon and then selecting the summation symbol menu item for the column or columns. Also the number of records on the bottom shows the total as well. But I would like the total to always show (as a count) so that when I export the query results to Excel, the total shows at the bottom of the Excel worksheet.
Thanks.