Create a query that searches many columns and returns many values

Deirdre

Board Regular
Joined
Feb 28, 2002
Messages
137
I have a table in Access set up like this:


Excel 2007
ABCDEFGHI
1NameAttribute 1Attribute 2Attribute 3Attribute 4Attribute 5Attribute 6Attribute 7Attribute 8
2John Doe 1jokersmiles a lotcalmuniquefriendlysmartfunnyspecial
3John Doe 2great friendleadertalkativeloves to laughsupportivefunnysmartnice
4John Doe 3quick thinkerloves recessdaydreamsjokerhappychillappreciativefriendly
5John Doe 4smartloves to learnsmiles a lottalkativegreat attittudehappypositive attitudewelcoming
6John Doe 5positive attitudesmartkinduniquegreat friendhappyenergeticenthusiatic
7John Doe 6talkativeloves schoolpositive attitudeappreciativeprettyhappygreat teammategreat friend
Sheet1


I have another table in Access set up like this:

Excel 2007
AB
1AttributesCorrected attribute
2smartsmart
3admireadmire
4always happyhappy
5amazingamazing
6amazing friendamazing friend
7appreciativeappreciative
8artisticartistic
9athelticathletic
10athlecticathletic
11athleticathletic
Sheet2


I need to write a query that will take the Corrected Attribute data in the 2nd table - search the 1st table, then return the names that meet it.

For example:
"Smart" should return, John Doe 1, John Doe 2, John Doe 4, John Doe 5

If there is a better way I should set up the data or maybe even use Excel, I am open to all suggestions.

Thank you!
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Re: Create a query that searches many columns and returns one many values

Yes, there is a design issue with your original table. You should not have repeating similar fields going across. It violates the rules of data normalization and makes tasks like the one you are trying to do much harder than they need to be.

Your table should just have three fields:
Name
Attribute Number
Attribute Value


So each name would have 8 records instead of 1 record with 8 fields.
Then, you only need to query against one field.
 
Last edited:
Upvote 0
Re: Create a query that searches many columns and returns one many values

I am afraid I do not follow. I'm sure it's me as my brain is mush today.
Kids were asked to write down a word that describes their classmates. Some kids wound up with 18 descriptors(attributes), some kids 8. The attribute number is just a header - all of those columns are really the same thing.

The attributes for each child do not repeat across. Which is why some have few than others. If 3 kids thought John Doe 1 was smart, it's only listed once.

My apologies if I made this more complicated. Long day.
 
Upvote 0
Re: Create a query that searches many columns and returns one many values

The attribute number is just a header -
all of those columns are really the same thing.
Yes, that is a big indicator that they should all be one field, not multiple fields.
Don't get confused by the Attribute Number, it is really just a counter for that person (and really does not have much meaning outside of that). It may be unnecessary altogether.

Your data for the first few people would look like this:
Code:
[TABLE="width: 275"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Attribute Number[/TD]
[TD]Attribute Value[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]1[/TD]
[TD]joker[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]2[/TD]
[TD]smiles a lot[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]3[/TD]
[TD]calm[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]4[/TD]
[TD]unique[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]5[/TD]
[TD]firendly[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]6[/TD]
[TD]smart[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]7[/TD]
[TD]funny[/TD]
[/TR]
[TR]
[TD]John Doe1[/TD]
[TD]8[/TD]
[TD]special[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]1[/TD]
[TD]great friend[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]2[/TD]
[TD]leader[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]3[/TD]
[TD]talkative[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]4[/TD]
[TD]loves to laugh[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]5[/TD]
[TD]supportive[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]6[/TD]
[TD]funny[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]7[/TD]
[TD]smart[/TD]
[/TR]
[TR]
[TD]John Doe2[/TD]
[TD]8[/TD]
[TD]nice[/TD]
[/TR]
</tbody>[/TABLE]
Note now when you are searching for particular values, you only need to search one field (not 8).
 
Last edited:
Upvote 0
Re: Create a query that searches many columns and returns one many values

A database table for this table could also be structured like this:
----------------------------------
| Person     | PersonAttribute   |
----------------------------------
| John Doe 1 | joker             |
| John Doe 2 | great friend      |
| John Doe 3 | quick thinker     |
| John Doe 4 | smart             |
| John Doe 5 | positive attitude |
| John Doe 6 | talkative         |
| John Doe 1 | smiles a lot      |
| John Doe 2 | leader            |
| John Doe 3 | loves recess      |
| John Doe 4 | loves to learn    |
| John Doe 5 | smart             |
| John Doe 6 | loves school      |
| John Doe 1 | calm              |
| John Doe 2 | talkative         |
| John Doe 3 | daydreams         |
| John Doe 4 | smiles a lot      |
| John Doe 5 | kind              |
| John Doe 6 | positive attitude |
| John Doe 1 | unique            |
| John Doe 2 | loves to laugh    |
| John Doe 3 | joker             |
| John Doe 4 | talkative         |
| John Doe 5 | unique            |
| John Doe 6 | appreciative      |
| John Doe 1 | friendly          |
| John Doe 2 | supportive        |
| John Doe 3 | happy             |
| John Doe 4 | great attittude   |
| John Doe 5 | great friend      |
| John Doe 6 | pretty            |
| John Doe 1 | smart             |
| John Doe 2 | funny             |
| John Doe 3 | chill             |
| John Doe 4 | happy             |
| John Doe 5 | happy             |
| John Doe 6 | happy             |
| John Doe 1 | funny             |
| John Doe 2 | smart             |
| John Doe 3 | appreciative      |
| John Doe 4 | positive attitude |
| John Doe 5 | energetic         |
| John Doe 6 | great teammate    |
| John Doe 1 | special           |
| John Doe 2 | nice              |
| John Doe 3 | friendly          |
| John Doe 4 | welcoming         |
| John Doe 5 | enthusiatic       |
| John Doe 6 | great friend      |
----------------------------------



The fuzzy matching is another kind of problem - so using ID's as in Joe's query would be what you are aiming for (each user supplied and possibly misspelled or variant description should match to a single ID or a single "Correct Spelling")
 
Last edited:
Upvote 0
Re: Create a query that searches many columns and returns one many values

A-HA! Now I follow!

Thank you very much!
 
Upvote 0
Re: Create a query that searches many columns and returns one many values

Thank you!!!
 
Upvote 0

Forum statistics

Threads
1,214,389
Messages
6,119,232
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top