Question

I am using MS Access 2010.

I am trying to create a table with three columns by joining different sections of the same table

the dataset is

ID Date      Job Title                                              Count of ID
-- --------- ------------------------------------------------------ -----------
 1 13-May-14 Security Guards                                                 15
 2 13-May-14 Interpreters and Translators                                    22
 3 13-May-14 Laborers and Freight, Stock, and Material Movers, Hand           1
 4 13-May-14 Maintenance and Repair Workers, General                         23
 5 13-May-14 Protective Service Workers, All Other                           54
 6 13-May-14 Logisticians                                                    65
 7 02-Apr-14 Security Guards                                                 88
 8 02-Apr-14 Interpreters and Translators                                    22
 9 02-Apr-14 Laborers and Freight, Stock, and Material Movers, Hand          44
10 02-Apr-14 Maintenance and Repair Workers, General                         77
11 02-Apr-14 Protective Service Workers, All Other                           66
12 02-Apr-14 Logisticians                                                     8

and the query is

SELECT ctrjob.[Job Title], ctrjob.[Count of ID], 

(Select ctrjob.[Count of ID] from  ctrjob 
where ctrjob.[Job Title] = ctrjob.[Job Title] and ctrjob.[Date] = #4/2/2014#)

FROM ctrjob where [ctrjob].[Date] = #5/13/2014# ; 

I want my finished table to create a table that places the number of contractors in each job title on 5/13/2014 next to the number from 4/2/2014. The goal is to do a comparison of the change in the number of workers.

But I keep getting an error message that

At most one record can be returned by the subquery

But all I want is for it to return the one corresponding record from the other date. Each time it is executed it should only return the number in job category X on 4/2/2014.

I don't want to use a transform/crosstab because the full dataset has too many dates and I want to use a form to toggle dates in the end. The list of job titles is identical across all dates. I am using MS Access 2010.

Was it helpful?

Solution

Instead of a subquery, use a join:

SELECT a.[Job Title], a.[Count of ID], b.[Count of ID]
FROM ctrjob a INNER JOIN
     ctrjob b ON a.[Job Title] = b.[Job Title]
WHERE a.Date = #4/2/2014# AND
      b.Date = #5/13/2014#
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top