Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Queries

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-21-2010, 09:53 PM
kulanga kulanga is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: Mar 2010
Posts: 7
kulanga is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 03-22-2010, 08:26 AM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

That just involves an OrderBy Clause.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #3  
Old 03-22-2010, 07:49 PM
kulanga kulanga is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: Mar 2010
Posts: 7
kulanga is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 03-22-2010, 08:29 PM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

It still sounds like a sorting problem to me.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #5  
Old 03-22-2010, 09:03 PM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,223
pbaldy is on a distinguished road
Default

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
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #6  
Old 03-22-2010, 09:17 PM
kulanga kulanga is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: Mar 2010
Posts: 7
kulanga is on a distinguished road
Default

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.
Reply With Quote
  #7  
Old 03-23-2010, 06:44 AM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,223
pbaldy is on a distinguished road
Default

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
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #8  
Old 03-23-2010, 01:44 PM
kulanga kulanga is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: Mar 2010
Posts: 7
kulanga is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 03-23-2010, 03:20 PM
pbaldy's Avatar
pbaldy pbaldy is online now Windows XP Access 2007 (version 12.0)
Who is John Galt?
 
Join Date: Feb 2010
Location: Nevada, USA
Posts: 1,223
pbaldy is on a distinguished road
Default

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
MS Access MVP
www.BaldyWeb.com
Reply With Quote
  #10  
Old 03-24-2010, 06:16 AM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

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.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
Reply

Bookmarks

Tags
access 2007, queries

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excluding data in a query lpdds Queries 1 12-16-2009 05:06 PM
Use query to find and sum data kwelch Queries 3 11-23-2009 01:26 AM
report ordering when exporting and detail field ordering mws5872 Reports 5 06-30-2009 07:30 AM
Use form data in a query Zholt Forms 2 05-13-2009 05:59 PM
Update a field in a table after ordering data in two other fields majamer Queries 1 08-04-2008 01:30 AM


All times are GMT -8. The time now is 08:31 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.