Results 1 to 10 of 10
  1. #1
    kulanga is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    7

    Ordering data from a query

    Hi,
    I am newbie to Access. The database that I have designed has 4 fields namely BedNo, Dislike1,Dislike2 and Dislike3.
    The primary key is BedNo.
    I tried to create a select query to group the data according to the values in the Dislike columns. For example values in the Dislike columns can be 'Eggs', 'Soup' etc.


    The result I need to get is for example is to group the Bedno's which dislike 'Eggs', 'Soup' etc.

    Thank you in advance.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That just involves an OrderBy Clause.

  3. #3
    kulanga is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    7
    Thank u RuralGuy but the thing is that the values in the Dislike columns is random and differs from bed to bed.
    The columns look like the following.
    Bedno|Dislike1 | Dislike2 | Dislike3
    1A | Eggs | Soup |
    2A | Chicken|Icecream|

    Thank You

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It still sounds like a sorting problem to me.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    I think it's a normalization problem (repeating fields). If the table were normalized like

    1A Eggs
    1A Soup
    2A Chicken
    2A Ice cream

    it would be a simple matter to find the bed numbers that don't like Eggs.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    kulanga is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    7
    Thank You Paul and Rural Guy. I have already done a query for this. The SQL coding looks like the following:

    SELECT ResidentsMasterTable.BedNo
    FROM ResidentsMasterTable
    WHERE (((ResidentsMasterTable.Dislikes1) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes2) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes3) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes4) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes5) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes6) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes7) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes8) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes9) Like '*Eggs*')) OR (((ResidentsMasterTable.Dislikes10) Like '*Eggs*'))
    GROUP BY ResidentsMasterTable.BedNo;


    Using this I get the BedNo's who dislike Eggs. But the result I would to get is let's say Eggs or Soup as a column name and BedNo as a Row name. I tried the pivot table option but didn't understand it much.

    Thank You.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Given the sample data you posted above, what will your desired result look like? BTW, with 10 dislike fields, there's no question in my mind it should be designed differently.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    kulanga is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    7
    Hi Paul,
    the desired result is:

    Eggs | Soup| Tomatoes
    1A |2A | 1A
    3B | |

    The query should group the bedno's according to the random values eg. Eggs or Soup in the Dislike columns.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    I'm not sure how to achieve that; maybe Allan knows a way. The reverse would be fairly easy with the normalized design I mentioned:

    Eggs 1A, 3B
    Soup 2A
    Tomatoes 1A
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    There is probably a way to get the report desired but it seems to me that if you have too many items disliked you can run out of horizontal room on a report.

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

Similar Threads

  1. Excluding data in a query
    By lpdds in forum Queries
    Replies: 1
    Last Post: 12-16-2009, 08:06 PM
  2. Use query to find and sum data
    By kwelch in forum Queries
    Replies: 3
    Last Post: 11-23-2009, 04:26 AM
  3. Replies: 5
    Last Post: 06-30-2009, 09:30 AM
  4. Use form data in a query
    By Zholt in forum Forms
    Replies: 2
    Last Post: 05-13-2009, 07:59 PM
  5. Replies: 1
    Last Post: 08-04-2008, 03:30 AM

Tags for this Thread

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