Results 1 to 2 of 2
  1. #1
    acdougla17 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    4

    Tricky (for me) SQL Query using COUNT

    List all columns in Employee that have more than 2 corresponding rows in Assignment.

    The columns they have in common are Employee.id and Assignment.eid.


    My method of thinking for this is to look for each time id = eid and the count the number of times it appears in table Assignment. I have tried at least 5 different times and cant get anything working. I am pretty new to SQL and I think I am having a hard time with certain questions because I approach like I would in a programming class.


    Here are a couple of my recent attempts.

    SELECT *
    FROM Employee WHERE EXISTS (SELECT eid FROM Assignment WHERE id = eid AND (SELECT COUNT(eid) FROM Assignment HAVING Count(eid) > 2));

    SELECT * FROM Employee WHERE EXISTS (SELECT eid, COUNT(eid) FROM Assignment WHERE id = eid AND HAVING COUNT(eid) > 2);

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Try something like this - I just got it to work on a couple of tables I rigged up just for this query.

    The two Tables [Table1 & Table2] have Fields named 'One', 'Two', 'Three' . . . [I know . . . corny . . . ]!

    It works for me.

    Code:
     
    SELECT Table1.One, Count(Table2.Two) AS NumberOfRecs
    FROM Table1 LEFT JOIN Table2 ON Table1.One = Table2.One
    GROUP BY Table1.One
    HAVING (((Count(Table2.Two))>4))
    ORDER BY Table1.One;
    I hope this helps!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query with max value and max count
    By Fabdav in forum Queries
    Replies: 1
    Last Post: 10-13-2011, 07:14 AM
  2. Tricky Values in a Combo Box
    By vt800c in forum Forms
    Replies: 5
    Last Post: 05-19-2011, 01:33 PM
  3. count query
    By lmp101010 in forum Access
    Replies: 6
    Last Post: 08-02-2010, 02:31 PM
  4. count query
    By lmp101010 in forum Queries
    Replies: 1
    Last Post: 08-01-2010, 12:20 PM
  5. Replies: 1
    Last Post: 04-01-2010, 05:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums