Results 1 to 5 of 5
  1. #1
    Marko is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2012
    Posts
    3

    Select first row

    Hello,

    I'm a newbie in Access so if someone could help:



    I have a table that is a result of an another query:

    seg_name Soll Soll2
    3DFL0402KS 4 MSG
    3DFL0402KS 6 OR
    3DFL0601KS 4 MSG
    3DFL0601KS 6 AND
    3DFL0602KS 4 MSG
    3DFL0602KS 6 OR
    3DFL0701KS 4 MSG
    3DFL0701KS 6 AND
    3DFL0702KS 4 MSG
    3DFL0702KS 6 OR
    3DFL0801KS 4 MSG
    3DFL0801KS 6 OR
    AND SO ON

    As a result I need one row of the mentioned table for each seg_name, with the lowest number in the "Soll" field.


    Thanks, Marko

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    what happens when you GROUP ON on seg_name and use MIN on Soll.

    Thanks

  3. #3
    Marko is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2012
    Posts
    3
    Nothing happens...

    SELECT [block-prioritet1].seg_name, Min([block-prioritet1].Soll) AS MinOfSoll, [block-prioritet1].Soll2
    FROM [block-prioritet1]
    GROUP BY [block-prioritet1].seg_name, [block-prioritet1].Soll2;

    Result:

    seg_name MinOfSoll Soll2
    3DFL0101KS 4 MSG
    3DFL0101KS 6 OR
    3DFL0102KS 4 MSG
    3DFL0102KS 6 OR
    3DFL0401KS 4 MSG
    3DFL0401KS 6 OR
    3DFL0402KS 4 MSG
    3DFL0402KS 6 OR
    3DFL0601KS 6 AND
    3DFL0601KS 4 MSG

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Code:
    SELECT [block-prioritet1].seg_name, Min([block-prioritet1].Soll) AS MinOfSoll 
     FROM [block-prioritet1]
    GROUP BY [block-prioritet1].seg_name;

    Code:
    SELECT 
    	[block-prioritet1].seg_name, 
    	[block-prioritet1].Soll, 
    	[block-prioritet1].Soll2
    FROM 
    	[block-prioritet1] 
    	INNER JOIN 
    	(
    		SELECT 
    			[block-prioritet1].seg_name, 
    			Min([block-prioritet1].Soll) AS MinOfSoll
    		FROM 
    			[block-prioritet1]
    		GROUP BY 
    			[block-prioritet1].seg_name
    	)
    	AS Query1 
    	ON 
    	([block-prioritet1].seg_name = Query1.seg_name) 
    	AND 
    	([block-prioritet1].Soll = Query1.MinOfSoll);
    Thanks
    Last edited by recyan; 04-26-2012 at 05:36 AM. Reason: addition of another code

  5. #5
    Marko is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2012
    Posts
    3

    reply

    Thank you it was very helpful!

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

Similar Threads

  1. Select Into VBA
    By snoopy2003 in forum Programming
    Replies: 3
    Last Post: 08-17-2011, 09:20 AM
  2. Replies: 8
    Last Post: 04-21-2011, 05:29 PM
  3. Replies: 4
    Last Post: 03-17-2011, 06:17 AM
  4. Replies: 1
    Last Post: 10-22-2010, 10:11 AM
  5. Select MAX ( ) +1
    By marco in forum Access
    Replies: 2
    Last Post: 05-05-2010, 03:51 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