Results 1 to 7 of 7
  1. #1
    sugat11 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2016
    Posts
    4

    updating single row per group in access query

    Hi,



    I need a query to update first row per each group with a vale of 1.
    Example:
    table1 have below fields

    ID marks cnt
    1 34
    1 22
    2 44
    2 4
    2 5
    6 7

    after query output should be
    ID marks cnt
    1 34 1
    1 22
    2 44 1
    2 4
    2 5
    6 7 1


    Please let me know your inputs. Advance Thanks

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you have insufficient information to provide what you want, you need another field to indicate a unique order - perhaps a date or uniqueID, or maybe (based on what you have provided) it is the record with the highest marks per ID? - which can be used to determine the 'first' record.

  3. #3
    sugat11 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2016
    Posts
    4
    what will be the query

    update table1
    set cnt =1
    where




    need to update table 1 field cnt with 1 for any row in group

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you still need to decide how you determine a single row from a unique value. In your data, marks might be unique but if two records had the same marks and ID there would be two records updated.

    You could try

    update table1
    set cnt=1
    where marks=dlookup("marks","table1","ID=" & ID)

    but I'm nut guaranteeing it will work a s you require

  5. #5
    sugat11 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2016
    Posts
    4
    Thansk Ajax it worked:

    Below is the input table :
    month site marks
    1 blr 56
    1 blr 22
    2 blr 11
    2 blr 66
    2 blr 88
    1 hyd 11
    1 hyd 55
    1 hyd 6
    2 hyd 1

    what will be the query to get the output as below:

    Month blr hyd
    1 78 66
    2 77 1

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    use a crosstab query - month - row header, site-column header - marks - value (sum)

  7. #7
    sugat11 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2016
    Posts
    4
    Much Thanks , you are a great help!!

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

Similar Threads

  1. Updating 2 tables from a single form
    By jpm in forum Forms
    Replies: 1
    Last Post: 06-17-2016, 03:50 AM
  2. Replies: 3
    Last Post: 08-02-2015, 12:42 AM
  3. Replies: 3
    Last Post: 06-25-2013, 10:57 AM
  4. Report graph not updating with each new group
    By mwinters13 in forum Access
    Replies: 7
    Last Post: 06-19-2013, 12:01 PM
  5. Replies: 5
    Last Post: 11-21-2011, 09:59 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